Foreword
It’s a bit unkind to directly describe the code, so according to the Chinese tradition, let’s describe it in one paragraph. . . . (My language skills are limited, so please bear with me)
Function
is used when registering users on the website, mainly to asynchronously verify whether the user name or email entered by the user has been registered without refreshing.
You must have seen this function. Most websites have it. I have always been interested in this function, so I have been studying jQuery + Ajax
I have integrated a function in the past few days. It is considered complete, but it is enough to handle the code for ordinary use (you can discover the more powerful functions by yourself)
File Description
reg.php //For the registration page
check_user.php // Verify the page for the user (optional GET, POST method)
jquery-1.7.1.js //Download address for the jQuery file: http://code.jquery.com/jquery-1.7.1.js (right-click and save as Just do it)
Code sample
reg.php registration page (contains 2 methods, please choose one)
Copy code The code is as follows:
PHP+Ajax Asynchronous Communication Registration Verification
< ;/body> The code is as follows:
header("Content-type:text/html;charset=gb2312");
//GET data (depends on asynchronous submission Submission method)
if($_GET['user']) { $user=$_GET['user']; //Database matching can be performed here, which is omitted this time Directly determine if($user=="admin")
echo "
The username has been registered! ";
else
echo "
Username can use";
}else{}
//POST method to obtain data (Depends on the submission method when submitting asynchronously)
if($_POST['user'])
{
$user=$_POST['user'];
//Database can be used here Match, this time it is omitted and directly judged
if($user=="admin")
echo "
The username has been registered! ";
else
echo "
Username can use";
}else{}
?>
The above two methods include post and get respectively, so it can be said that there are 4 methods to choose from, which should be sufficient for ordinary applications.
In addition, about other parameters in Ajax such as: request data type, ajax start operation and other events. Please refer to the ajax manual. I will not elaborate here. It is more complicated and recommended to use the first method.
With pictures:
http://www.bkjia.com/PHPjc/324836.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/324836.htmlTechArticleIt’s a bit unkind to directly describe the code in the preface, so according to the Chinese tradition, let’s describe it in one paragraph. . . . (My language skills are limited, please bear with me) Function When registering a user on the website...