jQuery的Ajax表单提交两次 [英] jquery ajax form submits twice
本文介绍了jQuery的Ajax表单提交两次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有我通过jQuery我捕捉并通过AJAX发送的形式。我的问题是,表单提交的时间超过一次我刷新页面。
我试图解除提交按钮,但随后的形式后的第一次提交通常张贴。任何帮助将是AP preciated
$('#exportForm)。递交(函数(){
$阿贾克斯({
键入:POST,
网址:$(本).attr(行动),
数据:$(本).serialize()
成功:函数(响应){
$('#exportForm)解除(提交);
的console.log(响应);
}
});
返回false;
});
解决方案
这是最有可能是您使用的是按钮
或提交
来触发Ajax事件。试试这个:
$('#exportForm)。递交(函数(五){
即preventDefault();
$阿贾克斯({
键入:POST,
网址:$(本).attr(行动),
数据:$(本).serialize()
成功:函数(响应){
的console.log(响应);
}
});
返回false;
});
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;
});
解决方案
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屋!
查看全文