asp.net xmlhttprequest to achieve user registration before the verification _ practical skills

Source: Internet
Author: User
Test to add 2 new items through environment VS2008
1:demo3.aspx
Copy Code code as follows:

query string, send service-side parameters
function createquerystring () {
var userName = document.getElementById ("UserName"). Value;
var querystring = "Username=" + userName;
return querystring;
}
function Runajax () {
Reference ' excerpt from a meaningful example in the book DEMO1. How HTML creates XMLHttpRequest object code '
Createxmlhttprequest ();
var querystring = "Ishaveuser.ashx?";
QueryString = querystring + createquerystring ()
+ "&timestamp=" + New Date (). GetTime (); append timestamp on//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! can be registered ...") {
settimeout ("document.getElementById" (' Validatemessage '). innertext= '; ", 2000);
}
}
}
}
<input id= "UserName"/><input id= "ishaveuser" button "type=" checks whether the user is registered "value=" onclick= (); /><span id= "Validatemessage" ></span>

2:ishaveuser Handler
Copy Code code as follows:

public class Ishaveuser:ihttphandler {
public void ProcessRequest (HttpContext context) {
System.Threading.Thread.Sleep (2000);
String userName = context. request.querystring["UserName"];
BOOL result = Read Database execution to determine if user name exists operation, return boolean value, omit code
if (result)
{
Context. Response.Write ("Congratulations! can register ...");
}
else {context. Response.Write ("This user exists, please replace ...");}
}
public bool IsReusable {get {return false;}}
}

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.