2012-03-19 60 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'); 
});