jQuery AJAX 表单提交两次 [英] jQuery AJAX form submits twice
本文介绍了jQuery AJAX 表单提交两次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个表单,我通过 jQuery 捕获并通过 AJAX 发送.我的问题是每次刷新页面时表单提交多次.
I've got a form that I'm capturing via jQuery and sending via AJAX. My problem is that the form submits more than once every time I refresh the page.
我试图解除提交按钮的绑定,但在第一次提交后表单会正常发布.任何帮助将不胜感激
I've tried to unbind the submit button but then the form is posted normally after the first submit. Any help would be appreciated
$('#exportForm').submit(function() {
$.ajax({
type: "POST",
url: $(this).attr('action'),
data: $(this).serialize(),
success: function(response) {
$('#exportForm').unbind('submit');
console.log(response);
}
});
return false;
});
推荐答案
很可能您正在使用 button
或 submit
来触发 ajax 事件.试试这个:
It's most likely that you're using a button
or submit
to trigger the ajax event. Try this:
$('#exportForm').submit(function(e){
e.preventDefault();
$.ajax({
type: "POST",
url: $(this).attr( 'action' ),
data: $(this).serialize(),
success: function( response ) {
console.log( response );
}
});
return false;
});
这篇关于jQuery AJAX 表单提交两次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文