0

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

检查用户.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代码:

$(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();
                }
            });
        });
4

1 回答 1

-1

我设法发现错误是什么。问题是,如果你包括像这样的数据库

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

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

于 2013-10-21T19:22:48.420 回答