1.create a new checkuser.htm File
<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Title> No title page </title>
<SCRIPT src = "checkuser. js" type = "text/JavaScript">
</SCRIPT>
</Head>
<Body>
<H1> simple Ajax-based data verification <HR/>
<Div>
<Span> User name: </span> <input id = "username" type = "text" onblur = "check (); "/> <span id =" checkresult "> </span>
</Div>
<Div>
<Span> password: </span> <input id = "password" type = "password"/>
</Div>
</Body>
</Html>
2. Create a checkuser. xml file.
<? XML version = "1.0" encoding = "UTF-8"?>
<User>
<Username> admin </username>
<Password> admin </password>
</User>
3. Create a checkuser. js file.
VaR XMLHTTP;
Function createxmlhttprequest ()
{
If (window. activexobject)
{
XMLHTTP = new activexobject ("Microsoft. XMLHTTP ");
}
Else if (window. XMLHttpRequest)
{
XMLHTTP = new XMLHttpRequest ();
}
}
Function check ()
{
Createxmlhttprequest ();
XMLHTTP. onreadystatechange = handlestatechange;
XMLHTTP. Open ("get", "checkuser. xml ");
XMLHTTP. Send (null );
}
Function handlestatechange ()
{
If (XMLHTTP. readystate = 4)
{
If (XMLHTTP. Status = 200)
{
Checkresult ();
}
}
}
Function checkresult ()
{
VaR xmluser = XMLHTTP. responsexml;
VaR xmlusername = xmluser. getelementsbytagname ("username") [0];
If (document. getelementbyid ("username"). value = xmlusername. childnodes [0]. nodevalue)
Document. getelementbyid ("checkresult"). innerhtml = "the user name has not been registered !!! ";
Else
Document. getelementbyid ("checkresult"). innerhtml = "the user name has not been registered !!! ";
}
Complete ~~!