Ruby on rails 第二次提交表单时,将呈现上一部分以及当前部分
我正在通过:remote=>true提交单个文本区域表单。它工作得很好,但是如果我提交表单两次而不重新加载页面,它会呈现部分3次。在第一次提交时,如果我输入新文本并再次提交,它将加载上一部分以及当前部分,结果显示为3次提交。它只提交到数据库两次,在页面刷新时,其中一次不可用。 我的控制器看起来是这样的:Ruby on rails 第二次提交表单时,将呈现上一部分以及当前部分,ruby-on-rails,ruby-on-rails-3,jquery,Ruby On Rails,Ruby On Rails 3,Jquery,我正在通过:remote=>true提交单个文本区域表单。它工作得很好,但是如果我提交表单两次而不重新加载页面,它会呈现部分3次。在第一次提交时,如果我输入新文本并再次提交,它将加载上一部分以及当前部分,结果显示为3次提交。它只提交到数据库两次,在页面刷新时,其中一次不可用。 我的控制器看起来是这样的: respond_to do |format| format.html { redirect_to(return_to) } format.js end 这是我的js: $(
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;
});
$('.comment_form').bind('ajax:success',function(){
$(this).closest('.post')。children('.comment_container')。prepend(“'public/comment',:object=>@comment)%>”;
$('.notice').html('新增评论');
$(this).children(':input').val('');
$(this).closest('.comment\u form\u div').slideUp();
返回false;
});
我只包含了jquery和jQueryUJS一次,并且我尝试过设置$.ajaxSetup({cache:false})代码>但无效
还有其他人遇到过这个问题吗?请注意,以防其他人遇到这个问题
我必须做:
$('#post_form').bind('ajax:complete', function(){
$('#post_form').unbind('ajax:success');
});