Ajax is mainly applied to JS. Ajax has no requirements for ASP. asp is only responsible for displaying and operating server data in the background.
Think like the following:
1. Write the first entry of the form (such as the user name)
2. Verification starts when an onblur event (out of focus) occurs. onblur = "checkusername ()"
3. js sends a request to the first ASP (assumed to be ajaxusername. asp). If this user is found in the database, 1 (all content of ajaxusername. asp is 1) is given.
<%
Response. Write "1"
%>
4. When JS receives the message, the checkuser () function is automatically executed.
Checkuser changes the background color of the user name line and displays "User already exists"
You can write the ASP part on your own. Below are some JS Code.
<SCRIPT>
/* The following functions do not need to be changed */
VaR Ajax;
Function createajax (){
If (window. XMLHttpRequest ){
Ajax = new XMLHttpRequest ();
} Else if (window. activexobject ){
Ajax = new activexobject ("Microsoft. XMLHTTP ");
}
}
Function senddata (URL _, sendtext _){
Ajax. Open ("Post", URL _, true );
Ajax. onreadystatechange = checkuser;
Ajax. Send (sendtext _);
}
Function checkajaxstatus (Ajax _){
If (Ajax _. readystate = 4)
If (Ajax _. Status = 200)
Return true;
Return false;
}
/* The above functions do not need to be changed */
Function checkuser (){
If (! Checkajaxstatus (Ajax) return;
// Processing the result returned by ASP. The server returns Ajax. asp, which is stored in the Ajax. responsetext attribute.
}
Function checkusername (){
Createajax ();
Senddata ("Ajax. asp", "username =" + name );
}
</SCRIPT>