小编tha*_*ook的帖子

jQuery验证器和使用AJAX的自定义规则

我阅读了关于jQuery验证器的回复,其中概述了一种根据数据库中的值检查用户名的方法.

我已经尝试过实现这个方法,但无论从PHP文件返回什么,我总是得到用户名已被取消的消息.

这是自定义方法......

$.validator.addMethod("uniqueUserName", function(value, element) {
  $.ajax({
      type: "POST",
       url: "php/get_save_status.php",
      data: "checkUsername="+value,
      dataType:"html",
   success: function(msg)
   {
      // if the user exists, it returns a string "true"
      if(msg == "true")
         return false;  // already exists
      return true;      // username is free to use
   }
 })}, "Username is Already Taken");
Run Code Online (Sandbox Code Playgroud)

这是验证码...

username: {
    required: true,
    uniqueUserName: true
},
Run Code Online (Sandbox Code Playgroud)

是否有一种特定的方式我应该从PHP返回消息.

谢谢

一个

validation ajax jquery jquery-validate

50
推荐指数
3
解决办法
7万
查看次数

标签 统计

ajax ×1

jquery ×1

jquery-validate ×1

validation ×1