First create an Ajax class (Ajax class)
and then create a new file form.html
---------------------- ----form.html-------------------------------
Copy code The code is as follows:
< ;script language="javascript" type="text/javascript">
function show(username){
var ajax = Ajax();
var noteobj = document.getElementById("note"); //Objectify the tag with the id of note
ajax.post("form.php",{username:username},function(data){ //The second username is the value that needs to be passed
noteobj. innerHTML = data; //data is the data obtained from the server
});
}
Finally create a new php file form.php
--------------------------form.html----------------------------- --------
Copy code The code is as follows:
header(" Content-type:text/html;charset=gb2312"); //Set the character set
$mysqli = new mysqli("localhost","root","123","demo"); //Open the demo database
$result = $mysqli->query("select * from zhanghao where name='{$_POST["username"]}'");
if($result->num_rows > 0) { //Determine whether to query the data
echo "User {$_POST["username"]} already exists! ";
}else{
echo "User {$_POST["username"]} can register";
}
?>
Open form.html in the browser and the following picture will appear:
![](http://www.bkjia.com/uploads/allimg/131016/1446163238-0.jpg)
Note: You need to create a table "zhanghao" in the MySQL database in advance
![](http://www.bkjia.com/uploads/allimg/131016/14461C593-1.jpg)
If you enter an existing name, the following prompt will appear:
![](http://www.bkjia.com/uploads/allimg/131016/1446164943-2.jpg)
If you enter a name that does not exist, the following prompt will appear:
![](http://www.bkjia.com/uploads/allimg/131016/14461CF6-3.jpg)
http://www.bkjia.com/PHPjc/324729.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/324729.htmlTechArticleFirst create an Ajax class (Ajax class) and then create a new file form.html -------- ------------------form.html----------------------------- Copy The code is as follows: script src="ajax....