且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

jQuery验证-有效后将不会触发远程方法

更新时间:2023-12-03 22:53:34

更新/解决方案:

查看jquery.validate.js的源代码,尤其是以下代码段:

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 ) {   ...

由于响应被评估为JSON,因此您应该调用return "true". 文档

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

响应被评估为JSON,对于有效元素必须为true"

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

但是,如果忽略了以下内容是隐式设置的事实,那么在查看 完全等于 测试为true的源代码时,可能会造成混乱. dataType: json

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

结束更新

在进行更多调查后,我会说您的"dataFilter"不应返回成功"

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

请参阅回调函数队列@ http://api.jquery.com/jQuery.ajax/

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

成功收到以下命令后,将立即调用

dataFilter回调 响应数据.它接收返回的数据和 dataType,并必须返回(可能已更改)数据以传递给 成功.

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.

我的猜测是您的JS尝试执行return success时失败了,因此没有进一步的验证请求被发送

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