我有一个表单,我通过jquery捕获并通过ajax发送。我的问题是,每次刷新页面时,表单都会提交多次。
我试图解除提交按钮的绑定,但是在第一次提交后,窗体就会正常发布。任何帮助将不胜感激
$('#exportForm').submit(function() {
$.ajax({
type: "POST",url: $(this).attr('action'),data: $(this).serialize(),success: function(response) {
$('#exportForm').unbind('submit');
console.log(response);
}
});
return false;
});
解决方法
很可能您正在使用按钮或提交触发ajax事件。尝试这个:
$('#exportForm').submit(function(e){
e.preventDefault();
$.ajax({
type: "POST",url: $(this).attr( 'action' ),success: function( response ) {
console.log( response );
}
});
return false;
});