dqjgf0982
dqjgf0982
2011-11-27 13:46
浏览 58

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
    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.

    点赞 评论
  • dpnzf48660
    dpnzf48660 2011-11-27 13:51

    Have you tried with:

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

    instead of:

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

    I have a similar problem and I resolved in this way. Additionally, I commented to you that in this way I didn't need put a json header.

    点赞 评论

相关推荐