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:
Note: You need to create a table "zhanghao" in the MySQL database in advance
If you enter an existing name, the following prompt will appear:
If you enter a name that does not exist, the following prompt will appear:
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....
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn