Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/87.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php jqueryvalidate:remote-一切正常,但没有显示错误_Php_Jquery_Jquery Validate - Fatal编程技术网

Php jqueryvalidate:remote-一切正常,但没有显示错误

Php jqueryvalidate:remote-一切正常,但没有显示错误,php,jquery,jquery-validate,Php,Jquery,Jquery Validate,我正在尝试使用Basistance jQuery插件实现电子邮件验证,并检查电子邮件地址是否存在 远程脚本正确返回true或false,但不会显示错误消息。其他验证(必需,电子邮件)工作正常 你知道我错过了什么吗 jQuery代码: jQuery().ready(function() { jQuery("#post").validate({ rules: { lid_email: { required: true,

我正在尝试使用Basistance jQuery插件实现电子邮件验证,并检查电子邮件地址是否存在

远程脚本正确返回
true
false
,但不会显示错误消息。其他验证(必需,电子邮件)工作正常

你知道我错过了什么吗

jQuery代码:

jQuery().ready(function() {
    jQuery("#post").validate({
        rules: {
            lid_email: {
                required: true,
                email: true,
                remote:  {
                    type: 'POST',
                    url:"email-check.php"
                }
            }
        },
        messages: {
            lid_email: {
                required: 'Gelieve een geldig e-mailadres in te vullen.<br>',
                email: 'Gelieve een geldig e-mailadres in te vullen.<br>',
                remote: 'Dit adres bestaat reeds. Gelieve een ander adres te kiezen.'
            }
        }
    })
    jQuery('#lid_email').blur(function() {
        jQuery("#post").validate().element( "#lid_email" );
    });
});
jQuery().ready(函数()){
jQuery(“#post”).validate({
规则:{
lid_电邮:{
要求:正确,
电子邮件:是的,
远程:{
键入:“POST”,
url:“email check.php”
}
}
},
信息:{
lid_电邮:{
必需:“Gelieve een geldig e-mailadres in te vullen.
”, 电子邮件:“Gelieve een geldig在te vullen的电子邮件地址。
”, 遥控器:“我的地址是芦苇。我的地址是基赞。” } } }) jQuery('#lid_email').blur(函数(){ jQuery(“#post”).validate().element(“#lid_email”); }); });
和远程脚本:

<?php 
header('Content-type: application/json');
require('../../../wp-blog-header.php');

$request = trim(strtolower($_POST['lid_email']));

if ( email_exists($request) == TRUE ) {
    echo json_encode(FALSE);
} else {
    echo json_encode(TRUE);
}
?>

您是否尝试过:

echo (email_exists($request) === true )?'true':'false'
而不是:

if ( email_exists($request) == TRUE ) {
    echo json_encode(FALSE);
} else {
    echo json_encode(TRUE);
}
我有一个类似的问题,我就这样解决了。此外,我向您评论说,通过这种方式,我不需要放置json头。

我找到了解决方案:

  • 我在一个Wordpress网站上使用了这个脚本,为了访问Wordpress函数,我加入了wp-blog-header.php

  • 显然,行
    require('../../../wp blog header.php
    破坏了json功能

  • 如果删除这一行,布尔值将正确发送,错误消息将显示

  • 我所要做的就是编写自己的用户函数,然后问题就应该解决了


@ptriek但是,你注意到firebug返回
false
true
时在这两种情况下都会发生什么吗?是的,我应该提到那里发生了一些奇怪的事情。我使用Charles proxy进行了检查,奇怪的是Charles报告了404,但返回了正确的布尔值。如果我使用firebug进行检查,它只报告了一个404-所以我猜问题就在那里…所以也许我应该重新表述我的问题:知道php脚本为什么会抛出404吗?@ptriek太奇怪了,我想你需要检查你的路径文件或htaccess。我刚刚找到了解决方案,是wp-blog-header.php Wordpress脚本打破了它。我已经写了一个问题的解释/so解决方案-但显然我的声誉太低,无法在8小时内回答我自己的问题:-等等:-)-谢谢你的帮助