2012-03-19 58 views
0

我通过以下方式提交单个文本区域表单:remote => true。它很好,但是如果我提交表单两次而没有重新加载页面,它会渲染局部3次。在第一次提交时,如果我输入新文本并再次提交,则会加载之前的部分以及当前的部分,导致看起来是3次提交。它只向数据库提交两次,在页面刷新其中一个消失。 我的控制器看起来像这样:第二次提交表单,呈现之前的部分以及当前的

respond_to do |format| 
    format.html { redirect_to(return_to) } 
    format.js 
    end 

和我,这是我的js:

$('.comment_form').bind('ajax:success', function(){ 
    $(this).closest('.post').children('.comment_container').prepend("<%= escape_javascript(render :partial => 'public/comment', :object => @comment) %>"); 
    $('.notice').html('<p>New Comment Added</p>'); 
    $(this).children(':input').val(''); 
    $(this).closest('.comment_form_div').slideUp(); 
    return false; 
}); 

我包括jQuery和jQuery的UJS只有一次,我已经尝试设置$.ajaxSetup({cache:false});,但无济于事。

有没有其他人遇到这个问题?

回答

0

只是为了防止任何人有这个问题。

我不得不这样做:

$('#post_form').bind('ajax:complete', function(){ 
    $('#post_form').unbind('ajax:success'); 
});