A situation will often encounter in the programming, which is not known in advance which data will require it, and must feed back the data after re-extracting the data from the server after selecting the data. For example, when the user chooses the province, we will immediately re-display all the provinces in the city. This situation generally needs to refresh the entire page before you can read it, but this is not only less efficient, but also is not very elegant. In fact, use JavaScript to combine micro-software XMLHTTP objects, we can read data from the server without refreshing, "slightly" can read data from the server, which is both professional and efficient.
Below we demonstrate this technology with a case where the user is registered.
1. First create a checkuser.asp file on the server to detect if the user exists, depending on whether the user has separate feedback 0 and 1
U_NAME = Request.QueryString ("u_name")
IF u_name exists the THEN
Response.write "0"
Else
Response.write "1"
END IF
2. Client HTML Design:
First, JavaScript code
Function check_user_exiss (form) {
U_NAME = form.u_name.value;
IF (u_name == null || u_name == ') {
Alert ("Please enter your username");
Return False;
}
InfoBoard = Document.GtelementByid ("CheckInfo");
InfoBoard.innertext = 'query ...';
MyURL = location.protocol "//" Location.hostName "/ CheckUser.asp? u_name =" u_name;
Retcode = OpenURL (MyURL);
Switch (retcode) {
Case "-2":
InfoBoard.innerHtml = ' Sorry font>, query failed'; Break;
Case "1":
InfoBoard.innerHtml = ' Congratulations font>,' u_name 'can use'; Break;
Case "0":
InfoBoard.innerhtml = ' Sorry font>, username' u_name 'has been used;
}
Return;
}
Function OpenURL (URL) {
Var objxml = new activXObject ("Microsoft.xmlhttp")
Objxml.open ("Get", URL, FALSE);
Objxml.send ();
Retinfo = Objxml.ResponseText;
IF (Objxml.status == "200") {
Return Retinfo;
}
Else {
Return "-2";
}
}
script>
Second, HTML form design: