0
我正在使用openinviter從gmail中檢索出效果很好的聯繫人。不過,當我使用jQuery調用Ajax調用來提交表單來檢索聯繫人時,smarty不會呈現。看來smarty只會呈現我不想做的頁面重新加載。所以,我的問題是如何在jQuery Ajax調用之後進行smarty渲染?如何在jQuery Ajax調用後呈現聰明
jQuery的AJAX調用
$(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>
</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" /> 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"/>
<!-- smarty code that needs to render after ajax call -->
{$fval} {$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>
你能給我一個如何使用ajax獲取smarty模板的例子嗎?這是我得到的,但不會工作。 $(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(''+ html +'').show(); jQuery(」#contactResponse「)。fadeIn('slow')。 load('{include file =「contactResponse.tpl」}'); }}); ;});}); – 2012-07-15 17:25:30
請在我的問題答案中查看這兩個鏈接,它們向您展示它如何在jquery中完成以及如何在php中獲取模板。 – Bjoern 2012-07-16 05:50:37