Ajax form creation verification example

Source: Internet
Author: User
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>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.