Ajax form submission implementation without refreshing the new registration example _ basic knowledge

Source: Internet
Author: User
This article mainly introduces the example of applying a form submitted by ajax to implement a new registration without refreshing the web page. For more information, see

The Code is as follows:


Var xmlHttp;
UName () // when the user name loses focus
{
If (all. uname. = "")
{
All. l1.innerHTML = "cannot be blank! ";
SetTimeout ("close (1)", 1500 );
Return;
}
Else
{
XmlHttp = new ActiveXObject ("Microsoft. XMLHTTP ");
XmlHttp. onreadystatechange = deal; // callback function
Var url = "aJax. aspx? User = '"+ all. uname. +"' "; // the user name to be checked.
XmlHttp. open ("get", url, true); // submit the form to the url in get mode, and start one step of processing.
XmlHttp. send (null); // send
}
}
Deal ()
{
// Alert (xmlHttp. readystate ++ xmlHttp. status );
If (xmlHttp. readystate! = 4)
{Return ;}

If (xmlHttp. status! = 200) // if it is equal to 500, it is an SQL statement or database error.
{Return ;}
//

Var num = xmlHttp. responseText; // receives the message sent by the server.
// Alert (num );
All. l1.innerText = "";
If (num> 0)
{
All. l1.innerText = "this user name has been used! ";
}
Else
{
All. l1.innerText = "√ ";
}

}

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.