PHP Tutorial Ajax Verify User name is available method
Initializes, specifies a function to process a function, send a request
//var poststr = "act=reply&bookid=" +bookid+ "&book_content=" + book_content;
Type:post or get
function Send_request (HTTP_REQUEST,URL,POSTSTR) {
Determine how and when the request is sent and whether the next code is executed synchronously
Http_request.open ("Post", url, True);
Http_request.setrequestheader ("Content-type", "application/x-www-form-urlencoded");
Http_request.send (POSTSTR);
}
Create an object-compatible multiple-browsing XMLHTTP creation method
function Create_obj () {
var http_request = false;
Start initializing the XMLHttpRequest object
if (window.xmlhttprequest) {//mozilla browser
Http_request = new XMLHttpRequest ();
if (http_request.overridemimetype) {//Set MIME category
Http_request.overridemimetype ("Text/xml");
}
}
else if (window.activexobject) {//IE browser
try {
Http_request = new ActiveXObject ("Msxml2.xmlhttp");
catch (e) {
try {
Http_request = new ActiveXObject ("Microsoft.XMLHTTP");
catch (e) {}
}
}
if (!http_request) {//exception, failed to create object instance
return false;
}
return http_request;
}
This code is to get the username value, send to the server driven by PHP query data return a ture false to verify that the user name is available.
function Getcheck () {
var http_request = Create_obj ();
Http_request.onreadystatechange = function () {
if (http_request.readystate = = 4) {
if (Http_request.status = = 200) {
var http_result2 = Http_request.responsetext;
If (' This login can use ' ==http_result2 ') {
Cancel_popup_win (' username ', true);
Username_check = true;
}else{
Popup_win (' username ', http_result2);
Username_check = false;
}
}
}
}
var Username=document.getelementbyid (' username '). value;
var poststr = "act=check&userid=" + username;
Send_request (Http_request, "http://www.111cn.net", poststr);
}
</script>
The invocation method is relatively simple
<li>
<span class= "DLM" ><em> setting Logins: </em>
<input tabindex= "1" class= "text_2 name=" username "id=" username "value=" "type=" text "maxlength=" " Autocomplete= "Off" onblur= "Getcheck ();" /> Login: 4-16/odd character/full digit/no content/underline/have full-width/have space/have uppercase/have character </span>
</li>