如何在 jQuery 验证器中使用 AJAX 检查值是否已存在

How to check whether a value already exists using AJAX in jQuery validator?

本文关键字:检查 AJAX 是否 存在 jQuery 验证      更新时间:2023-09-26
$.validator.addMethod("noanon", function(value) {
return ajaxFunction();
}, 'Username already exists.');

addMethod 函数接受 3 个参数。名称、实际运行的逻辑,最后是用于失败的默认消息。

name: {
 required: true,
 minlength: 2,
 noanon: true
},

现在,如果我使用 ajaxFunction,则会出现一些错误。

您可以使用

remote方法:

rules: {
    name: {
        remote : "script.php"
    }
},
messages: {
    name: {
        remote : "Page with this name is exists"
    }
}

在 PHP 中,您需要$_GET['name'] .

此处提供其他信息