这是来自注册表。此函数验证用户名是否可用。
jQuery:
/* Verifies if the username is available */
$.post('functions/usernameDisponibility.php',{usernamePHP:username},function(disponibility)
{
$('.usernameErrors').text(disponibility);
if(disponibility==true)
{
$('#username').css('border-color','#00ff00');
}else
{
$('#username').css('border-color','red');
$('.usernameErrors').text('Username unavailable');
}
});
PHP:
if(isset($_POST['usernamePHP'])&&!empty($_POST['usernamePHP']))
{
$username = $_POST['usernamePHP'];
$Connect = mysql_connect('localhost','root','');
mysql_select_db('phplogin');
$query= mysql_query("SELECT * FROM users WHERE username = '$username'");
$result= mysql_num_rows($query);
if($result==1)
{
echo false;
}else
{
echo true;
}
}
问题出在错误显示中。当 disponibility != true 时,它显示“用户名不可用”,但当它为 true 时,它显示“1”。我的猜测是“1”来自 PHP 脚本,但即使我这样做:
if(disponibility==true)
{
$('#username').css('border-color','#00ff00');
$('.usernameErrors').text('');
}else
“1”仍然很快出现,然后才被文本('')替换。根本不显示“1”怎么办?