PHP Ajax to verify that the user name is available method

Source: Internet
Author: User
Tags php tutorial

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>

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.