Original Ajax implementation without refreshing judgment on whether users can register

Source: Internet
Author: User

Recently, the project entered the end of the project, mainly to provide some training to the customer. Each time a customer registers for a system, all the information is displayed. After clicking OK, if the user name is in the background, it cannot be added, however, the information entered on the page may be gone, for example, the password items will be cleared. This is an unfriendly place. After you enter the user name in many forums on the internet, you will be able to determine whether the user can be filled out after you lose the focus. You will be able to add this function to the project ~~

Add JS in front-end devices

<! --
Var xmlHttp;
Function createXMLHttpRequest (){
If (window. ActiveXObject ){
XmlHttp = new ActiveXObject ("Microsoft. XMLHTTP ");
}
Else if (window. XMLHttpRequest ){
XmlHttp = new XMLHttpRequest ();
}
}

Function checkUserName (){
Var UserName = document. getElementById ('tbxmanagername ');
If (UserName. value = "")
Return;
CreateXMLHttpRequest ();
Var url = "check_user.aspx? UserName = "+ UserName. value;
XmlHttp. open ("GET", url, true );
XmlHttp. onreadystatechange = handleStateChange;
XmlHttp. send (null );
}

Function handleStateChange (){
If (xmlHttp. readyState = 4 ){
If (xmlHttp. status = 200 ){
Var isValid = xmlHttp. responseText;
Var checkResult = document. getElementById ("checkResult ");
CheckResult. innerHTML = (isValid = "true ")? " & nbsp; congratulations! ":" & nbsp; this user name already exists. Select the base user name! ";
}
}
}

Background check_user.aspx.csprivate void Page_Load (object sender, System. EventArgs e)
{
String UserName = Request. QueryString ["UserName"];

// Validate
Bool isValid = false;
Int count = 0;
Count = (new DPM. Sys. ManagerBR (). GetResultByCondition (ManagerDS. MANAGER_TABLE, "Manager_LoginName = '" + UserName + "'");
If (count = 0)
IsValid = true;

Response. Clear ();
Response. Write (isValid? "True": "false ");
Response. End ();
}

The running effect is as follows:
Registrable:

Cannot register:

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.