我正在使用 jquery 验证表单。我想使用ajax提交表单。当我将ajax调用放入validate的submitHandler()中时,浏览器挂起。这是怎么回事?
当我启用验证方法的调试时收到的错误消息是:
uncaught exception: [Exception... "Illegal operation on WrappedNative prototype object" nsresult: "0x8057000c (NS_ERROR_XPC_BAD_OP_ON_WN_PROTO)" location: "JS frame :: http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js :: f :: line 132" data: no]
这对我来说太神秘了,无法理解。
一些代码:
$(document).ready(function() {
$("#loginForm").validate({
debug: true,
errorLabelContainer: $('div.error'),
wrapper: 'li',
rules: {
last_name: {
required: true
}
},
messages: {
last_name: {
required: "Please enter your last name."
}
},
submitHandler: function(form){
$.ajax({
type: "POST",
url: "test.php",
data: form,
success: function(msg){
console.log( "Data Saved: " + msg );
},
error: function(msg){
console.log( "Error: " + msg);
}
});
}
});
});
该表单是一种非常普通的表单。通过标准 POST 提交效果很好。另外,验证工作正常...只是使用 ajax 提交部分让我失败。
最佳答案
您可能希望在发送表单之前序列化该表单 - 您可能不想发送 DOM 对象
编辑 RE:comment - 仅选择一些输入并序列化 -
$(form).find(":input[name=inp1] :input[name=inp2]").serialize()
关于javascript - 使用 jQuery 验证上传表单,在submitHandler() 中使用ajax...不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4039577/