jqueryphp:检查用户名是否已经存在

jqueryphp:检查用户名是否已经存在,php,jquery,ajax,Php,Jquery,Ajax,我正在尝试使用jQuery+Ajax+POST检查是否存在已在我的应用程序上注册的用户名 HTML <div class="form-group"> <label for="username" class="col-md-3 control-label">Username</label> <div class="col-md-9"> <input type="text" id="username" class=

我正在尝试使用jQuery+Ajax+POST检查是否存在已在我的应用程序上注册的用户名

HTML

<div class="form-group">
    <label for="username" class="col-md-3 control-label">Username</label>
    <div class="col-md-9">
        <input type="text" id="username" class="form-control" name="username" placeholder="Username">
    </div>
</div>
<div class="col-sm-9 col-sm-offset-3" id="userCheck">
    <div class="alert alert-info" id="userCheckLabel"></div>
</div>
PHP

<?php
require_once('../../core/class.user.php');
$user = new USER();
$uname = $_POST['username'];

$stmt = $user->runQuery("SELECT user_nameFROM users WHERE user_name=:uname ");
$stmt->execute(array(':uname'=>$uname));
$row=$stmt->fetch(PDO::FETCH_ASSOC);

if($row['user_name']==$uname) {
    print 'true';
} else {
    print 'false';
}
?>

我不包括class.user.php,因为它只处理PDO连接,如果我删除
If(data.html=='true')
连接按预期工作,消息就会出来

行为

如果我删除
if(data.html=='true')
,代码就会工作。但有了这个,它什么也不做,在控制台中没有错误。因此,我认为错误在于我处理PHP部分的方式。
有什么建议吗?

因为您返回的是字符串而不是HTML,所以您必须执行以下操作:-

$.post( "../core/lib/checkUserExist.php",{username: uname }, function( data ) {
     console.log(data);// check this and let me know the output
     if(data == 'true') {  // or try if(data)
       $('#userCheck').slideDown("slow");
       $('#userCheckLabel').text("This user already exist!")
    }
});

感谢您的回复,使用您的建议,我没有收到关于用户existOk的警报,文件路径有误,现在它按预期工作,谢谢@Andreeam很高兴帮助您:):)您没有发送用户名
函数checkUserExist(uname){$.post(../core/lib/checkUserExist.php“,{username:uname},函数(data){…
我得到了意外的令牌函数,我错过了它comma@splash58多亏了你,活到死,代码现在开始工作了!
$.post( "../core/lib/checkUserExist.php",{username: uname }, function( data ) {
     console.log(data);// check this and let me know the output
     if(data == 'true') {  // or try if(data)
       $('#userCheck').slideDown("slow");
       $('#userCheckLabel').text("This user already exist!")
    }
});