A simple Ajax-based data verification

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

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.