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