【问题标题】:How to make jQuery Validator remotely trigger errorPlacement?如何让 jQuery Validator 远程触发 errorPlacement?
【发布时间】:2012-05-18 11:03:00
【问题描述】:

谁能告诉我如何让 jQuery Validatorremote 函数时调用 errorPlacement 处理程序失败?我提供了一个简短的例子:

悬崖笔记:根据他们的文件,我必须输出 JSON,但我一定错过了什么,因为我只是回显 json_encode,还是提供了一个像 echo json_encode(array('result' => 0)) 这样的密钥在这个block of text中说。

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
echo false; // This should allow the errorPlacement to call shouldn't it?

【问题讨论】:

  • 你可能想回显json_encode(FALSE),因为现在你什么都没有回显。 (但如果我正确理解源代码,也不会触发错误。)

标签: php jquery validation


【解决方案1】:

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

<?php
echo 'false';

我已根据您的问题创建了jsfiddle。 pastebin 链接只返回单词“false”。

【讨论】:

  • 这太丑了。正如 Zombaya 所说,json_encode(FALSE) 是要走的路。
  • 理论上,json_encode(FALSE) 不会产生有效的 JSON,因为有效的 JSON 在其顶层有一个数组或一个对象
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-11-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多