The file is register.php in client <html> <head> <title> user Registration </title> <meta http-equiv = "Content-type "CONTENT =" text/html;charset=utf-8 "/> <script type =" Text/javascript ">//Create AJAX engine function Getxmlhttpobject
() {var XMLHttpRequest; Different browsers Get object XMLHttpRequest object method different if (window).
ActiveXObject) {XMLHttpRequest = new ActiveXObject ("Microsoft.XMLHTTP");
}else{XMLHttpRequest = new XMLHttpRequest ();
return XMLHttpRequest;
}/* Function Getxmlhttpobject () {//different browsers Get object XMLHttpRequest object method different var xmlHttp = null;
try{//firefox, Opera 8.0+, Safari xmlHttp = new XMLHttpRequest ();
}catch (e) {//internet Explorer try{xmlHttp = new ActiveXObject ("Msxml2.xmlhttp");
}catch (e) {xmlHttp = new ActiveXObject ("Microsoft.XMLHTTP");
} return xmlHttp;
} * * var myxmlhttprequest = "";
Verify that the user name exists a function checkname () {//Line Line 1 myxmlhttprequest = Getxmlhttpobject ();
Judge Create success? if (myxmlhttprequest) {//through MYXMLHTTThe Prequest object sends a request to a page//first parameter of the server to represent the request, and the "get"/"POST"///second parameter specifies the URL and the AJAX request to which page (essentially still the HTTP request)//The third parameter. True indicates the use of asynchronous mechanisms
, false indicates no asynchronous mechanism///NOTE: here if there is a space between "username" and "=", there will be an error, and the "username" cannot be received on the server side;
Note: If there is a space after "=" The space is also used as part of the value of the received username.
That is, the value of the username received on the server = "" (That is, a space) + Username value sent from the client.
var url = "/ajaxtest/registerprocess.php?username=" + $ ("Username1id"). Value;
Window.alert (URL);
Open Request Myxmlhttprequest.open ("get", url,true);
Specifies the callback function. Process is a function name myxmlhttprequest.onreadystatechange = process; Really send the request.
If the GET request is filled with null//If it is a POST request, fill in the actual data//Line Line 2 myxmlhttprequest.send (null);
}//Callback functions function process () {//window.alert ("This is a callback function" + myxmlhttprequest.readystate); I want to remove the data returned from the registerprocess.php page if (myxmlhttprequest.readystate = = 4) {//Fetch value, depending on the format of the return information//window.alert ("Clothing
Service return "+ Myxmlhttprequest.responsetext);
Line Line 4 $ (' Myresponse '). Value = Myxmlhttprequest.responsetext; } function $ (id) {return document.getElementById (ID); } </script> </head> <body> <form action = "" method = "POST" > User name: <input type = "Text" Name = "username1" id = "Username1id" > <input type = "button" onclick = "checkname ();" Value = "Verify user name" > <input style = "border-width:0;" color:red ' type = ' text ' id = ' myresponse ' > <br/> password: <input type = ' password ' name = ' password ' ><b R/> e-mail: <input type = "text" name = "Email" ><br/> <input type = "submit" VALUE = "User Registration" > </f
orm> <form action = "" method = "POST" > Username: <input type = "text" name = "UserName2" > <br/> Password: <input type = "password" name = "Password" ><br/> e-mail: <input type = "text" name = "Email" ><br /> <input type = "submit" VALUE = "User Registration" > </form> </body> </html>
//the file for registerprocess.php, <?php//receiving data $username = $_get["username" on server side;
if ($username = = "Shunping") {echo "User name is not available";
}else{echo "User name available"; echo "Username:". $username;//Line Line 3?