AJAX applications registered users instant detection

Source: Internet
Author: User

The no refresh mechanism of Ajax makes it possible to display the registration name in the registration system instantly.

Common user registration is user input user name, the background program detects whether the user name in the database is duplicated and makes a sign of success and failure (when the user registers the duplicate will return to register), or a little humanization is to add a detection button after the User Name text box, let the user detect and then do registration.

The above operation, for the user experience is more "bad", a good user experience is: When the user entered the user name, the web system should be able to immediately check and real-time display, and check and display without affecting the current page operation. This is the requirement to "get data asynchronously," which is the strength of Ajax

function display

When you enter a user name that already exists (such as Cnbruce, Cnrose), the page will display a duplicate that cannot be registered (FALSE), otherwise the display can be registered (TRUE), which provides a quick reference to the user's registration and the user experience is supreme.

So here's how to implement this function.

In fact, as the t1.htm source code, you can see the essence of Ajax

First, define the XMLHTTP object

var xmlHttp = false;
try {
 xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
 try {
  xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
 } catch (e2) {
  xmlHttp = false;
 }
}
if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
 xmlHttp = new XMLHttpRequest();
}

For a description of this section, please see

Next is the Custom function

function callServer() {
 var u_name = document.getElementById("u_name").value;
 if ((u_name == null) || (u_name == "")) return;
 var url = "cu.asp?name=" + escape(u_name);
 xmlHttp.open("GET", url, true);
 xmlHttp.onreadystatechange = updatePage;
 xmlHttp.send(null);
}

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.