dqjgf0982 2011-11-27 13:46
浏览 79
已采纳

jQuery Validate:remote - 一切正常,但没有显示错误

I'm trying to implement email validation using the Bassistance jQuery plugin, with a check if the email adress exists.

The remote script returns correcctly true or false, however - no error message is shown. Other validation (required, email) works fine.

Any idea's what I'm missing here?

The jQuery code:

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" );
    });
});

And the remote script:

<?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);
}
?>
  • 写回答

2条回答 默认 最新

  • dshp9580656 2011-11-27 21:52
    关注

    I found the solution:

    • I'm using the script in a Wordpress site, and included wp-blog-header.php in order to have access to the Wordpress functions.

    • Apparently the line require('../../../wp-blog-header.php breaks the json functionality

    • If I remove this line, the booleans are sent correctly, and the error message shows up.

    • All I have to do, is write my own user_exists-function, and then the problem should be solved.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 来真人,不要ai!matlab有关常微分方程的问题求解决,
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算