尝试验证用户名是否已存在于我的数据库中时(我正在使用 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();
}
});
});