开发者

jquery validation always fails

Why is the following validation function always failing. It even fails if I have both return case with true.

$.validator.addMethod("validate_old_password", function(value, element){
    $.ajax({
        url: '/users/ajaxPage_password_v开发者_开发技巧alidation/',
        type: 'POST',
        dataType: 'text',
        debug: true,
        data: {
            password: $("#id_old_password").val()
        },
        success: function(response){
            if (response == "True") {
                console.log('aa')
                return true;
            }// correct PW
            return false; // bad PW
        }
    })
}, "password not valid");


I believe its because of the deferred execution.

When the "validate_old_password" method is called it simply kicks off the ajax call and continues to the end of the method, it won't wait around for the response.

You may want to consider using the remote validation options in the validation plugin.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜