简体   繁体   English

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

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

$.validator.addMethod("noanon", function(value) {
return ajaxFunction();
}, 'Username already exists.');

The addMethod function takes 3 arguments. addMethod函数采用3个参数。 A name, the logic to actually run, and lastly, the default message to use for failures. 名称,实际运行的逻辑,最后是用于失败的默认消息。

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

Now if I use the ajaxFunction, there sems to be some error which is appearing. 现在,如果我使用ajaxFunction,则可能会出现一些错误。

You can use remote method: 您可以使用remote方法:

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

In PHP you take $_GET['name'] . 在PHP中,您可以使用$_GET['name']

Additional information here 附加信息在这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM