我有以下的code应该通过Ajax提交表单,而无需重新加载页面,该页面:
I have the following code which is supposed submit a form via Ajax without having to reload the page:
$( document ).on('submit', '.login_form', function( event ){
event.preventDefault();
var $this = $(this);
$.ajax({
data: "action=login_submit&" + $this.serialize(),
type: "POST",
url: _ajax_login_settings.ajaxurl,
success: function( msg ){
ajax_login_register_show_message( $this, msg );
}
});
});
但出于某种原因,尽管事件preventDefault();
功能,从实际发射应该prevent的形式,它实际上火。
However for some reason, despite the event.preventDefault();
function which is supposed to prevent the form from actually firing, it actually does fire.
我的问题是,我怎么prevent上述形式的重新加载页面?
My question is, how do I prevent the above form from reloading the page?
感谢
不重视文档上的监听器,而不是提交按钮使用的点击处理程序,并类型更改为按钮。
don't attach a listener on document instead use a on click handler on the submit button and change the type to button.
<button id="form1SubmitBtn">Submit</button>
$('#form1SubmitBtn').click(function(){
//do ajax here
});
编码快乐!
上一篇:传递选择多选择值到控制器的动作控制器、多选、动作、择值到
下一篇:jQuery的阿贾克斯.load。获得X(高)TML相关的错误(&QUOT;不匹配的标签,预期:其中,/ BR&GT;&QUOT;)不匹配、错误、标签、load