Ajax php validate no function <p>Below is my html, I need input dialog without form format.</p> <pre><code>&lt;!DOCTYPE&gt; &lt;html&gt; &lt;head&gt; &lt;script&gt; var username; function myFunction() { //input dialog username = prompt("Please enter your name", ""); if (username != "") { checkNameValidate(); } else { alert("The name is empty, please insert your name"); } } function checkName() { //ajax to validate.php var xmlhttp = new XMLHttpRequest(); xmlhttp.open("GET", "validate.php?username=" + username, false); xmlhttp.send(null); //doFunction(); } function doFunction() { //function } &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;input type="button" onclick="myFunction()" value="Name" /&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>below is validate.php code, my database name is testajax, </p> <pre><code>&lt;?php $username=$_POST["username"]; mysql_connect("localhost","root",""); mysql_select_db("testajax"); $query1 = mysql_query("select * from user where name='$username'"); if(mysql_num_rows($query1)&gt;0){ echo "&lt;script language=javascript&gt;alert('The name have used');&lt;/script&gt;"; } ?&gt; </code></pre> <p>This is my work, but cannot validate user, what is my wrong, anyone can help correction?</p>