1
$.fn.form.settings.rules["checkUsername"] = function(value) {
var url = "/Index/checkUsername";
var res = true;
$.ajax({
    async : false,
    url : url,
    type : "POST",
    data : {
        username : value
    },
    dataType: "json",
    success: function(data){
        if(data['code']==1){
            res = false;
        }else {
            res = true;
        }
        console.log(res);
        return res;
    }
});
};

var validation = {
   username : {
        identifier : 'username',
        rules : [
            { type : 'empty', prompt : 'Please enter your email' },
            { type : 'checkUsername', prompt : 'Username already existed' }
        ]
    }
};

It did not work, but the console log is right.

haxtbh
  • 3,467
  • 1
  • 21
  • 22
Kuma Chow
  • 11
  • 1

1 Answers1

0

I am using similar kind of validation but not doing an ajax call.

Curious: Can you put a logging statement just after the ajax call and see if the validation rule is returning before the ajax call?

I would also consider putting the return statement below the ajax call (still inside of the validation function)

Tab
  • 1,702
  • 2
  • 19
  • 39