Jquery Rails-仅在视觉效果完成后调用Ajax

Jquery Rails-仅在视觉效果完成后调用Ajax,jquery,ruby-on-rails,ruby,ajax,Jquery,Ruby On Rails,Ruby,Ajax,我只想在我的淡出效果结束后进行ajax调用。 这是我的简单代码: <script type="text/javascript"> function closeIt(id) { $(id).slideUp(); } </script> <%= link_to_remote('Delete', :url => {:action => "ajaxdestroy", :controller => "blog_comments",

我只想在我的淡出效果结束后进行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>

函数closeIt(id){
$(id.slideUp();
}
{:action=>“ajaxdestroy”、:controller=>“blog_comments”、:blog_post_id=>@blog_post.id、:id=>comment.id}、:before=>“closeIt('comment#{comment.id}”)、:update=>“blogPostComments”、:confirm=>“你确定吗?”)%>

现在生成的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>

因此调用了effect closeIt函数,但ajax调用在slideUp效果之前完成。如何在上一个closeIt函数的回调中调用Ajax函数

谢谢使用

<a onclick="return closeThat(39);" href="#">Delete</a>



function closeThat(id) {
    if (confirm('Are you sure?')) {
        closeIt('comment'+id, function() {
            new Ajax.Updater('blogPostComments', '/blog_comments/ajaxdestroy/'+id+'?blog_post_id=6', {
                asynchronous: true,
                evalScripts: true,
                parameters: 'authenticity_token=' + encodeURIComponent('Xzvq2/0BlbVi3eVCxW5TGcKmap3nrVC1SiG76W+bVGc=')
            });
        });
    }
    return false;
}


function closeIt(id, callback) {
    $(id).slideUp(400, callback);        
}

函数关闭(id){
如果(确认('你确定吗?')){
closeIt('注释'+id,函数(){
新的Ajax.Updater('blogPostComments','/blog_comments/ajaxdestroy/'+id+'?blog_post_id=6'{
是的,
evalscript:对,
参数:'authenticity_token='+encodeURIComponent('Xzvq2/0BlbVi3eVCxW5TGcKmap3nrVC1SiG76W+bVGc=')
});
});
}
返回false;
}
函数closeIt(id,回调){
$(id).slideUp(400,回调);
}

好的,我在创建后使用javascript解决了这个问题。我从link_to_remote中删除了:before和:confirm符号,并在生成的元素中添加了一个“id”字段

 <%= link_to_remote 'Cancella', {:url => {:action => "ajaxdestroy", 
                                          :controller => "blog_comments", 
                                          :blog_post_id => @blog_post.id, 
                                          :id => comment.id},
                                 :update => "blogPostComments"},
                                 {:id => "delete#{comment.id}"} %></p>

     <script>   
         var onClick<%=comment.id%> = new Function($('#delete<%= comment.id%>').attr('onClick'));  //get the ajax call autogenerated        
         function nuova() {   //define a new function to wrap it
              if (confirm('Are you sure?')) { //move here the confirm message
                  $('#comment<%= comment.id%>').hide(600,onClick<%=comment.id%>);
              }
              return false;     
    }                                   
         $('#delete<%= comment.id%>').removeAttr('onclick').click(nuova);
    </script>
{:action=>“ajaxdestroy”,
:controller=>“博客评论”,
:blog\u post\u id=>@blog\u post.id,
:id=>comment.id},
:update=>“blogPostComments”},
{:id=>“删除{comment.id}”}%>

var onClick=新函数($('#delete').attr('onClick')//自动生成ajax调用 函数nuova(){//定义一个新函数来包装它 如果(确认('you sure?'){//将确认消息移到此处 $('#comment').hide(600,onClick); } 返回false; } $('#delete')。删除文本('onclick')。单击(nuova);

不是最干净的,但这是一个解决方案。现在,Delete ajax调用只有在效果终止后才提交

谢谢Christophe,但是我如何才能从rails代码生成此javascript代码?事实上,javascript代码是自动生成的{:action=>“ajaxdestroy”,:controller=>“blog_comments”,:blog_post_id=>@blog_post.id,:id=>comment.id},:before=>“closeIt('comment{comment.id}”),:update=>“blogPostComments”,:confirm=>“you sure?”)%>生成javascript代码。我可以使用:before符号定义在Ajax调用之前调用的javascript函数,但我不知道如何将Ajax调用作为:before函数的回调调用