Native Ajax submission PHP background receive no problem

Source: Internet
Author: User
Tags cdata

varxmlHttp; if(window. ActiveXObject) {xmlHttp=NewActiveXObject ("Microsoft.XMLHTTP"); } Else if(window. XMLHttpRequest) {xmlHttp=NewXMLHttpRequest (); }functionGetappcaptcha (CDATA) {if(Iscaptcha) {return} Iscaptcha=true; Xmlhttp.open ("POST", aaa.php ');        Xmlhttp.setrequestheader ("Content-type", "application/x-www-form-urlencoded");        Xmlhttp.setrequestheader ("X-requested-with", "XMLHttpRequest");         Xmlhttp.send (Disposedata (CDATA));  Xmlhttp.onreadystatechange = function (data) {if (xmlhttp.readystate = = 4) && (Xmlhttp.status = = 200))                 {var sdata = Json.parse (data.currentTarget.response);                if (Sdata.error_code = = 0) {//Verify success//dry point what Isclick = false;                    }else if (Sdata.error_code = = 1048) {//More than four times Isclick = true; Document.queryselector ('. Pop_click_box '). style.display = ' block '}else{//Authentication failed Tipfun (SDATA.ERROR_MSG);            }} else {Isclick = false; }        }     }

The above code because PHP does the Ajax checksum needs

Xmlhttp.setrequestheader ("Content-type", "application/x-www-form-urlencoded");        Xmlhttp.setrequestheader ("X-requested-with", "XMLHttpRequest");
---------------------------------------------------------------------------------------
PHP determines the principle of Ajax requests:

When sending an AJAX request, we can create a custom header message by XMLHttpRequest This object, in the jquery framework, for the $.ajax, $.get, or $.post methods that request the content of the Web page. It will pass a http_x_requested_with parameter to the server, PHP is in the header layer to determine whether the AJAX request, corresponding to $_server[' Http_x_requested_with '] judgment.

Attention:
      • In general $_server[' Http_x_requested_with ') is XMLHttpRequest by default
      • $_server[' Http_x_requested_with ' can also be custom created, using Xmlhttprequest.setrequestheader (Name,value);
-------------------------------------------------------------------
The submitted data requires the Disposedata method to be processed into the corresponding string to
//Pass-the- parameter encapsulation    functionDisposedata (data) {varstrdata = ", num = 0;  for(varKeyinchdata) {            if(num = = 0) {strdata= key + ' = ' +Data[key]; }Else{strdata+ = ' & ' + key + ' = ' +Data[key]; } num++; }        returnstrdata; }

A string like this gives the backstage name= place &bankcard=2321323123123&phone=13800138000

Native Ajax submission PHP background receive no problem

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.