jQuery远程验证错误未显示

时间:2013-10-20 21:18:41

标签: php jquery jquery-validate

我在尝试验证数据库中是否已存在用户名时遇到jQuery问题(我使用jQuery远程函数)。我得到一个firebug响应,如果它存在则为false或者如果不存在则为true,但远程消息永远不会显示。

checkuser.php:

<?php require("includes/connection.php"); ?>

<?php

header('Content-type: application/json');

$uname = mysql_real_escape_string($_REQUEST["juser"]);
$query = mysql_query("SELECT username from person where username='$uname'");
$find=mysql_num_rows($query);
 if($find>0){
        $output = json_encode(false);
 }
 else{
        $output = json_encode(true);
 }
 echo $output;

?>

jquery-code:

$(function(){
            $('#formReg').validate({
                rules:{
                    'juser': {
                        required: true,
                        minlength: 4,
                        remote: {
                            url: "checkuser.php",
                            async:false
                        }
                    },
                    'jpass':  {required: true, minlength: 8},
                    'jpass2': { required: true, minlength: 8, equalTo: "#jpass" },
                    'jemail': { required: true, email: true },
                    'jname':  { required: true, minlength: 3 },
                    'jlastname': { required: true, minlength: 3 }

                },
                messages: {
                    'juser': {  required: 'Debe ingresar usuario', 
                                minlength: 'Debe ser minimo 4 caracteres',
                                remote: 'Usuario ya esta registrado'
                             },
                    'jpass': {  required: 'Debe ingresar password', 
                                minlength: 'Minimo 8 caracteres'},
                    'jpass2': { required: 'Debe ingresar password', 
                                minlength: 'Minimo 8 caracteres', 
                                equalTo: 'Las contraseñas deben ser iguales' },
                    'jemail': { required: 'Debe ingresar un correo electrónico', email: 'Debe ingresar un correo electrónico con formato correcto' },
                    'jname': { required: 'Debe ingresar su nombre', minlength: 'Minimo 3 Caracteres'},
                    'jlastname': { required: 'Debe ingresar su apellido', minlength: 'Minimo 3 Caracteres'}
                },
                debug: true,
                submitHandler: function(form){
                    form.submit();
                }
            });
        });

1 个答案:

答案 0 :(得分:-1)

我设法发现错误是什么。问题是,如果你包括像

这样的数据库
<?php require("includes/connection.php"); ?>

并且里面有注释,远程函数返回false / true + php的注释。