gpt4 book ai didi

jquery - 在表单验证的提交处理程序ajax中出现Uncaught TypeError : form.序列化不是函数

转载 作者:行者123 更新时间:2023-12-01 08:41:55 24 4
gpt4 key购买 nike

在控制台中出现此错误 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!')}
}

});

}
});

最佳答案

根据documentation对于 jQuery 验证插件,submitHandler 回调获取 native 表单作为唯一参数。

native 表单没有 serialize() 方法,因为它是 jQuery 方法。
您必须将 native 表单包装在 $()

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!')}
}
});
});
});

关于jquery - 在表单验证的提交处理程序ajax中出现Uncaught TypeError : form.序列化不是函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46081360/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com