How can I force jQuery Validate to check for duplicate username in database?

前端 未结 5 1090
春和景丽
春和景丽 2021-01-03 11:52

I\'m coming into the middle of this project so I\'m having to do a bit of re-writing because of sloppy code. I am using jQuery 1.6.1 and Validate 1.8.1.

First, here\

5条回答
  •  抹茶落季
    2021-01-03 12:18

    While you adding addMethod you should return true or false from server side.

    and also that value have to be returned from addMethod.

    ie something like this

    $.validator.addMethod("checkAvailability",function(value,element){
        var parameter="action=checkusername&username="+username;
        $.ajax({
              url: "dbquery.php",
              type: "POST",
              async: false,
              data: parameter
              success:function(output)
                     {
                        return output
                     }
         });
    },"Sorry, this user name is not available");
    

提交回复
热议问题