我想在完成FadeOut效果後才能進行ajax調用。 這是我簡單的代碼:Rails - 僅在視覺效果完成後才調用Ajax
<script type="text/javascript">
function closeIt(id) {
$(id).slideUp();
}
</script>
<%= link_to_remote('Delete', :url => {:action => "ajaxdestroy", :controller => "blog_comments", :blog_post_id => @blog_post.id, :id => comment.id}, :before => "closeIt('comment#{comment.id}')", :update => "blogPostComments", :confirm => 'Are you sure?') %></p>
現在生成的HTML看起來像這樣:
<a onclick="if (confirm('Are you sure?')) { closeIt('comment39'); new Ajax.Updater('blogPostComments', '/blog_comments/ajaxdestroy/39?blog_post_id=6', {asynchronous:true, evalScripts:true, parameters:'authenticity_token=' + encodeURIComponent('Xzvq2/0BlbVi3eVCxW5TGcKmap3nrVC1SiG76W+bVGc=')}); }; return false;" href="#">Delete</a>
所以效果closeIt函數被調用,但效果基本show效果之前Ajax調用完成。如何在先前closeIt函數的回調函數中調用Ajax函數?
感謝
謝謝Christophe,但我怎麼能讓這個JavaScript代碼從rails代碼生成?實際上JavaScript代碼是自動生成的 – coorasse
你是什麼意思「從rails代碼生成」? – alste
<%= link_to_remote('Delete',:url => {:action =>「ajaxdestroy」,:controller =>「blog_comments」,:blog_post_id => @ blog_post.id,:id => comment.id},: before>>「closeIt('comment#{comment.id}')」,:update =>「blogPostComments」,:confirm =>'Are you sure?')%>生成javascript代碼。我可以使用:在符號之前定義一個在Ajax調用之前調用的javascript函數,但我不知道如何使Ajax調用被稱爲:before函數的回調函數 – coorasse