Javascript 检查注册表中的用户名

Javascript 检查注册表中的用户名,javascript,php,html,mysql,Javascript,Php,Html,Mysql,在下面的代码中,我希望在提交表单之前检查用户名是否可用。我在用户名字段中使用了onchange()事件 HTML代码: <form method="post" action="RegConf.php"> <p> <input type="text" id="username" name="username" value="" placeholder="Username" onchange="check_ava()">

在下面的代码中,我希望在提交表单之前检查用户名是否可用。我在用户名字段中使用了
onchange()
事件

HTML代码:

<form method="post" action="RegConf.php">
    <p>
        <input type="text" id="username" name="username" value="" placeholder="Username" onchange="check_ava()"> 
        <span id='ava_result'>
    </p>
    <p>
        <input type="password" id="password" name="password" value="" placeholder="Password">
    </p>
    <p>
        <input type="password" id="confPassword" name="confPassword" value="" placeholder="Confirm Password" onchange="check()"> 
        <span id='message'>
    </p>
    <p>
        <input type="text" name="email" value="" placeholder="Email">
    </p>
    <p>
        <input type="text" name="phone" value="" placeholder="Phone">
    </p>
    <p>
        <input type="text" name="address" value="" placeholder="Address">
    </p>
    <p class="submit">
        <input type="submit" id="submit" name="commit" value="Submit">
        <button type="reset" value="Reset">Reset</button>
    </p>
</form>

您必须使用远程方法:

<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.13.1/jquery.validate.min.js"></script>  
<script> 
    $(function() {
                $('#form-validation').validate({

                    rules: {

                        username: {
                            required: true,
                            remote: {
                            url: "check_username.php",
                            type: "post"
                     }
                        },

                    },
                    messages: {
                      val_number: 'Please enter a Value!',

                    }
                });  
            });
</script>

您面临的问题是什么?请控制响应并查看您得到了什么定义“不工作”不工作=当我键入用户名时,不会检查它是否可用或不可用您的查询是否运行或您得到的是一个空白屏幕?
$registeredName[] = //select all names in your databse using select and store here as array, 

$requestedName  = $_POST['username'];
if(in_array($requestedName,$registeredName))
{
    echo 'false';
}
else
{
    echo 'true';
}