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" %>