Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

how to render smarty after a jquery ajax call

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
copperspeed
Smarty n00b


Joined: 15 Jul 2012
Posts: 3

PostPosted: Sun Jul 15, 2012 4:15 am    Post subject: how to render smarty after a jquery ajax call Reply with quote

I am using openinviter to retrieve contacts from gmail which works great.However, when I use jquery with ajax call to submit a form that retrieves contacts smarty does not render. It seems that smarty only renders a page reload which I don't want to do. So, my question is how can I make smarty render after jquery ajax call?

jquery ajax call

$(document).ready(function(){
$('input[name="Submit"]').click(function() {
var query = $('#frmContact').serialize();
$.ajax({type: "POST",url: "google_friends.php",data: query,cache: false,success:function (html) $('#errid').html('<span style="font-size:12px; font-family:Arial, Helvetica, sans-serif; color:#FF0000;">'+html+'</span>').show();}});
return false;});});
</script>

<div>
<!--- Smarty code that needs to render after jquery ajax call -->
{if count($contacts) == 0 }
<span id="errid" >{$msg}</span>
<p>
<!-- Form that is used by jquery ajax -->

<form class="Form StaticForm" id="frmContact" action="" name="frmContact" method="post">
<input type="hidden" name="provider_box" value="gmail" />
<ul>
<li>
<input type="text" name="email_box" value="email" onBlur="if (this.value=='') this.value='email';" onFocus="if(this.value=='email') this.value='';" />
</li>
<li>
<input type="password" name="password_box" value="password" onBlur="if(this.value=='') this.value='password';" onFocus="if(this.value=='password') this.value='';" />
</li>

<li class="noBorderTop"><input class="Button WhiteButton Button18 trueB" type="button" value="Submit" name="Submit" />
<label>
&nbsp;</label>
</li>
</ul>
</form>
</p>
<!-- smarty code that needs to render after ajax call -->
{else}
<span id="errid" ></span>
<p>
<form class="Form StaticForm2" action="" name="invtfrm" method="post">
<ul>
<li style="float:left;margin-left:120px;">
<input type="checkbox" name="checkall" onClick="return doCheckAll();" style="vertical-align:0" />&nbsp;Select All

</li>
<li style="float:left;"><div class="box-dividerCenter1 gradient"></div></li>
<!-- smarty code that needs to render after ajax call -->
{foreach from=$contacts key=fkey item=fval}

<li style="float:left;margin-left:120px;">
<input type="checkbox" name="email[]" value="{$fkey}" style="vertical-align:0"/>&nbsp;
<!-- smarty code that needs to render after ajax call -->
{$fval}&nbsp;&nbsp;&nbsp;&nbsp;{$fkey}

</li>
<li style="float:left;"><div class="box-dividerCenter1 gradient"></div></li>
{/foreach}
<li class="noBorderTop"><a class="Button WhiteButton Button18" href="#" id="sbmtbtn" ><strong>Invite</strong><span></span></a></li>
{/if}
</ul>
</form>
Back to top
View user's profile Send private message
carpii
Smarty Rookie


Joined: 06 Sep 2008
Posts: 18

PostPosted: Mon Jul 16, 2012 10:34 pm    Post subject: Reply with quote

This isnt really a smarty question.

Check your PHP code which handles the ajax request (and then asks smarty to render it).
Most likely this is where the problem lies
Back to top
View user's profile Send private message
dmm2020
Smarty Rookie


Joined: 29 Nov 2009
Posts: 27

PostPosted: Sat Oct 13, 2012 4:19 pm    Post subject: Reply with quote

My concern with the response is Smarty renders the entire page and does not merely update the HTML. AJAX has to take over once the HTML is loaded into the browser and it seems that Smarty and Ajax does not mix very reliably. I would dearly like to see working examples or a module developed that blends AJAX into Smarty better.
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Sat Oct 13, 2012 9:30 pm    Post subject: Reply with quote

Here is an article how Smarty and Ajax can work together http://www.ibm.com/developerworks/opensource/library/wa-aj-smarty/index.html

Or google for "Smarty ajax" you will find lots of articles and examples
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP