我可能会连续多次远程提交表单。对于这种特殊情况,去抖不是一种选择。我正在为使用 .submit()
提交的远程表单寻找相当于 .abort()
的 jQuery,这样我就可以在提交新表单时取消所有以前的提交。
提前致谢, 加勒特
最佳答案
我所做的是附加到表单的 beforeSend 事件,将 xhr 对象存储为表单数据的一部分,并在新请求排队时中止它:
$('form').bind("ajax:beforeSend", function(evt, xhr) {
console.log('Enqueued new xhr request');
var prevXhr = $(this).data('current-xhr');
if (prevXhr) {
prevXhr.abort();
console.log('Aborting previous xhr request');
}
$(this).data('current-xhr', xhr);
});
您仍然可以使用 simple 形式的 :remote => true
选项。
关于ruby-on-rails-3 - 杀死jquery ajax表单提交,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5085515/