Add two new projects in the test environment VS2008
1: DEMO3.ASPX
Copy codeThe Code is as follows: // query string and SEND server Parameters
Function createQueryString (){
Var userName = document. getElementById ("userName"). value;
Var querystring = "userName =" + userName;
Return querystring;
}
Function RunAjax (){
// Refer to 'How to create XMLHttpRequest object Code' in DEMO1.HTML from meaningful examples in the book'
CreateXMLHttpRequest ();
Var queryString = "IsHaveUser. ashx? ";
QueryString = queryString + createQueryString ()
+ "& TimeStamp =" + new Date (). getTime (); // append a timeStamp to the URL to prevent browser caching
XmlHttp. onreadystatechange = handleStateChange;
XmlHttp. open ("GET", queryString, true );
XmlHttp. send (null );
Document. getElementById ('validatemessage'). innerText = 'checking. Please wait ...';
}
Function handleStateChange (){
If (xmlHttp. readyState = 4 ){
If (xmlHttp. status = 200 ){
Var result = xmlHttp. responseText;
Document. getElementById ("validateMessage"). innerText = result;
If (result = "Congratulations! You can register ..."){
SetTimeout ("document. getElementById ('validatemessage'). innerText =''; ", 2000 );
}
}
}
}
<Input id = "userName"/> <input id = "IsHaveUser" type = "button" value = "check whether a user is registered" onclick = "RunAjax (); "/> <span id =" validateMessage "> </span>
2: IsHaveUser HandlerCopy codeThe Code is as follows: public class IsHaveUser: IHttpHandler {
Public void ProcessRequest (HttpContext context ){
System. Threading. Thread. Sleep (2000 );
String userName = context. Request. QueryString ["userName"];
Bool result = reads the database and performs an operation to determine whether the user name exists. A boolean value is returned, omitting the code.
If (result)
{
Context. Response. Write ("Congratulations! You can register ...");
}
Else {context. Response. Write ("this user exists. Replace ...");}
}
Public bool IsReusable {get {return false ;}}
}