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);
}