简体   繁体   English

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

[英]How to make jQuery Validator remotely trigger errorPlacement?

Can anyone please tell me how I can get the jQuery Validator to call the errorPlacement handler when a remote function fails? 谁能告诉我remote功能失败时如何让jQuery验证程序调用errorPlacement处理程序? I have provided a short example: 我提供了一个简短的示例:

Cliff Notes: According to their documents, I have to output JSON, but I must have missed something because do I just echo out json_encode, or do I provide a key like echo json_encode(array('result' => 0)) as it says in this block of text . Cliff Notes:根据他们的文档,我必须输出JSON,但是我一定错过了一些事情,因为我只是回显json_encode,还是提供像echo json_encode(array('result' => 0))之类的键在此说的文本块

JS: 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: PHP:

<?php
echo false; // This should allow the errorPlacement to call shouldn't it?

I think you need to echo false as a string from your PHP script: 我认为您需要从PHP脚本中将false作为字符串回显:

<?php
echo 'false';

I've created a jsfiddle based on your question. 我根据您的问题创建了一个jsfiddle The pastebin link just returns the word "false". pastebin链接仅返回单词“ false”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM