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 = "√ ";
}
}