Jquery远程验证显示1为错误消息

时间:2012-08-02 06:18:58

标签: php jquery jquery-validate

这是我的客户端验证脚本:

 jQuery('#myForm_members').validate({
        rules:{
            user_userpassword2:{equalTo:'#user_userpassword'},
            user_username: {required: true,remote: 
                               {url:'option/members/member.php?task=check_user_name',type:'post',async: false}}            
        },
        messages:{
            user_userpassword2:{equalTo:'Password mismatched.'},
            user_username:{remote:'User name exists.'}            
        }
        });

服务器端脚本:

    $num_rows=$this->count_rows($sql);
    if($num_rows>0)
        echo 0;
    else
        echo 1; 

当此验证返回false时,它可以正常工作 Working on false condition

但是当此验证返回true时,它不起作用并返回1作为错误 Returing 1 as error

1 个答案:

答案 0 :(得分:3)

尝试:

header('content-type: application/json; charset=utf-8'); 
if($r>0)
    echo json_encode( false );
else
    echo json_encode( true );