Ajax authentication Username

Source: Internet
Author: User

Execute the ajax method when the data in the User Name box changes

<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head runat = "server">
<Title> Add a user </title>
<Script type = "text/javascript">
// Empty Form Verification
Function check ()
{

Var a = document. getElementById ("account ");

If (a. value. length = 0)
{
Alert ("the user name cannot be blank! ");
A. focus ();
Return false;
}
Var B = document. getElementById ("neckname ");
If (B. value. length = 0)
{
Alert ("nickname cannot be blank! ");
B. focus ();
Return false;
}
Var c = document. getElementById ("pwd ");
If (c. value. length = 0)
{
Alert ("the password cannot be blank! ");
C. focus ();
Return false;
}
Var d = document. getElementById ("pwd0 ");
If (d. value. length = 0)
{
Alert ("OK! ");
D. focus ();
Return false;
}
Return true;
}
// Verify whether the user name exists
Var xmlHttp;
Function isExist ()
{


Var account = document. getElementById ("account ");

If (window. ActiveXObject)
{
XmlHttp = new ActiveXObject ("Microsoft. XMLHTTP ");
}
Else
{
XmlHttp = new XMLHttpRequest ();
}

Var s = "checkUser. aspx? Id = "+ document. getElementById (" account "). value. toString ();

XmlHttp. onreadystatechange = handlStateChage;
XmlHttp. open ("GET", s, true );

XmlHttp. send (null );

}
Function handlStateChage ()
{

If (xmlHttp. readyState = 4) // indicates that the request is complete, 0 = not initialized; 1 = loading; 2 = Loading complete; 3 = interaction in progress; 4 = completion
{
If (xmlHttp. status = 200) // Request status, 200 indicates normal return
{
Document. getElementById ("result"). innerHTML = xmlHttp. responseText;
}
}
}

</Script>
</Head>
<Body>
<Form id = "form1" runat = "server">
<Div>
<Table style = "margin: 0 auto">
<Tr>
<Td colspan = "3" align = "center"> </Tr>
<Tr>
<Td> User name: </td>
<Td> <input type = "text" id = "account" name = "account" onchange = "isExist ();"/> </td>
<Td> <div id = "result" style = "color: # FF0000"> </div> </td>
</Tr>
<Tr>
<Td> nickname: </td>
<Td colspan = "2"> <input type = "text" id = "neckname" name = "neckname"/> </td>

</Tr>
<Tr>
<Td> password: </td>
<Td colspan = "2"> <input type = "password" id = "pwd" name = "pwd"/> </td>

</Tr>
<Tr>
<Td> Confirm Password: </td>
<Td colspan = "2"> <input type = "password" id = "pwd0" name = "pwd0"/> </td>

</Tr>
<Tr>
<Td colspan = "3" align = "center">
<Asp: Button ID = "okbtn" runat = "server" Text = "add" Height = "24px" Width = "62px"
OnClientClick = "return check ();" onclick = "okbtn_Click"/> </td>

</Tr>
</Table>
</Div>
</Form>
</Body>
</Html>

 

Verify the page, remove other scripts, and leave only the following script page status errors

<% @ Page Language = "C #" AutoEventWireup = "true" CodeBehind = "checkUser. aspx. cs" Inherits = "Web. checkUser" %>

 

 

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.