jquery validation - remote method won't trigger after valid

后端 未结 2 1693
心在旅途
心在旅途 2020-12-11 02:25
email1: {
                    required: true,
                    blacklist: true,
                    beanEmailValidator: true,
                    minlength: 6,
           


        
2条回答
  •  盖世英雄少女心
    2020-12-11 03:02

    UPDATE/SOLUTION:

    Looking at the source code of jquery.validate.js, particularly this snippet:

    success: function(response) {
        validator.settings.messages[element.name].remote = previous.originalMessage;
        var valid = response === true;
    
        if ( valid ) {   ...
    

    Since the response is evaluated as JSON, you are expected to call return "true". This is also pointed out in the documentation

    "The response is evaluated as JSON and must be true for valid elements"

    However, it can be quite confusing when looking at the source code that does an exactly equals test for true, if you neglect the fact that the following is implicitly set dataType: json

    end update


    Upon investigating some more, I'd say that your 'dataFilter' should not be returning 'success'

    Refer to Callback function queues @ http://api.jquery.com/jQuery.ajax/

    dataFilter callback is invoked immediately upon successful receipt of response data. It receives the returned data and the value of dataType, and must return the (possibly altered) data to pass on to success.

    My guess is that your JS breaks on trying to do return success and thus no further validation requests are sent

提交回复
热议问题