Php 如何使jQuery验证程序远程触发errorPlacement?

Php 如何使jQuery验证程序远程触发errorPlacement?,php,jquery,validation,Php,Jquery,Validation,有谁能告诉我,当远程功能失败时,如何让调用0)) JS: var validator = $("form#signup").validate({ onfocousout: true, rules: { email: { required: true, email: true, remote: { type: "POST", url

有谁能告诉我,当
远程
功能失败时,如何让
调用
处理程序?我提供了一个简短的例子:

克里夫注释:根据他们的文档,我必须输出JSON,但我肯定错过了什么,因为我是只是回显JSON_encode,还是像中所说的那样提供了一个类似
回显JSON_encode(array('result'=>0))

JS:

var validator = $("form#signup").validate({
    onfocousout: true,
    rules: {
        email: {
            required: true,
            email: true,
            remote: {
                type: "POST",
                url: 'test.php',
                data: {
                    email: function() {return $("#email").val();}
                }
            }
        },
        errorPlacement: function(error, el) {
            console.log('ERR' + $(el).attr('id'));
        }
    }
});
<?php
echo false; // This should allow the errorPlacement to call shouldn't it?
PHP:

var validator = $("form#signup").validate({
    onfocousout: true,
    rules: {
        email: {
            required: true,
            email: true,
            remote: {
                type: "POST",
                url: 'test.php',
                data: {
                    email: function() {return $("#email").val();}
                }
            }
        },
        errorPlacement: function(error, el) {
            console.log('ERR' + $(el).attr('id'));
        }
    }
});
<?php
echo false; // This should allow the errorPlacement to call shouldn't it?

我认为您需要将PHP脚本中的
false
作为字符串进行回显:

<?php
echo 'false';

您可能希望回显
json\u encode(FALSE)
,因为现在您根本不回显任何内容。(但如果我正确理解了源代码,那么就不会触发错误。)这太难看了。正如Zombaya所说,
json\u encode(FALSE)
是正确的选择。理论上,
json\u encode(FALSE)
不会生成有效的json,因为有效的json在其顶层有一个数组或一个对象