In form validate's submithandler ajax getting Uncaught TypeError: form.serialize is not a function
In form validate's submithandler ajax getting Uncaught TypeError: form.serialize is not a function
在控制台中收到此错误 Uncaught TypeError: form.serialize is not a function 。如何修复表单验证提交处理程序的 ajax 中的此错误?
$('#form').validate({
errorClass: 'fieldError',
onkeyup: false,
onblur: false,
errorElement:'label',
submitHandler: function(form) {
$.ajax({
url: form.action,
type: form.method,
data: form.serialize(),
success: function(response) {
if (response == false)
{alert('could not submit!')}
}
});
}
});
根据 jQuery 验证插件的 documentation,submitHandler
回调获取本机表单作为唯一参数。
原生形式没有 serialize()
方法,因为它是 jQuery 方法。
您必须将原生形式包装在 $()
中
submitHandler: function(form) {
var $form = $(form);
$.ajax({
url : $form.attr('action'),
type : $form.attr('method'),
data : $form.serialize(),
success : function(response) {
if (response == false) {
alert('could not submit!')}
}
});
});
});
在控制台中收到此错误 Uncaught TypeError: form.serialize is not a function 。如何修复表单验证提交处理程序的 ajax 中的此错误?
$('#form').validate({
errorClass: 'fieldError',
onkeyup: false,
onblur: false,
errorElement:'label',
submitHandler: function(form) {
$.ajax({
url: form.action,
type: form.method,
data: form.serialize(),
success: function(response) {
if (response == false)
{alert('could not submit!')}
}
});
}
});
根据 jQuery 验证插件的 documentation,submitHandler
回调获取本机表单作为唯一参数。
原生形式没有 serialize()
方法,因为它是 jQuery 方法。
您必须将原生形式包装在 $()
submitHandler: function(form) {
var $form = $(form);
$.ajax({
url : $form.attr('action'),
type : $form.attr('method'),
data : $form.serialize(),
success : function(response) {
if (response == false) {
alert('could not submit!')}
}
});
});
});