Ajax synchronization mode browser compatibility problems upload. phpPHPcode & lt ;! DOCTYPEhtmlPUBLIC & quot;-W3CDTDXHTML1.0TransitionalEN & quot; www. w3.orgTRxhtml1DTDxhtml1-transitional. dtd & quot; & ajax synchronization mode browser compatibility issues
Upload. php
PHP code
Untitled DocumentF
Script function GetXmlHttpObject () {var XMLHttp = null; try {XMLHttp = new XMLHttpRequest ();} catch (e) {try {XMLHttp = new ActiveXObject ("Msxml2.XMLHTTP");} catch (e) {XMLHttp = new ActiveXObject ("Microsoft. XMLHTTP ") ;}}return XMLHttp;} function upload () {var flag = false; var XMLHttp = GetXmlHttpObject (); var url =" upload_deal.php "; var dataStr = "hour =" + document. getElementById ("hour "). value; XMLHttp. Open ("POST", url, false); XMLHttp. setRequestHeader ("content-type", "application/x-www-form-urlencoded"); XMLHttp. send (dataStr); var resTest = XMLHttp. responseText; resTest = resTest. trim (); var response_compent = "true"; if (resTest! = Response_compent) {document. getElementById ("status"). innerHTML = resTest;} else flag = true; return flag;} script
Backend upload_deal.php
PHP code
if($_REQUEST['hour']==1) { echo "true"; } else { echo "false"; }
If you want to submit hour to the background for judgment, and then submit the form and jump based on the returned value. if true is correct, the system submits the form and jumps. if false is incorrect, the system does not submit the form, skip, or prompt. However, this code is no problem in non-ie kernel browsers such as firefox and Google, but all of them are redirected using ie (I am 9. Try to add the status of the callback function to judge onreadystatechange, but all browsers will not execute it. once onreadystatechange is passed, it will go directly to the final return.
PHP code
XMLHttp.onreadystatechange=function() { if(XMLHttp.readyState==4&&XMLHttp.status==200) { var resTest=XMLHttp.responseText; resTest=resTest.trim(); var response_compent="true"; if(resTest!=response_compent) { document.getElementById("status").innerHTML=resTest; } else flag=true; } }
------ Solution --------------------
I searched for it. javascript has no trim () method, right? ResTest = resTest. trim ();
------ Solution --------------------
Discussion
Reference:
I searched for it. javascript has no trim () method, right? ResTest = resTest. trim ();
This is really a problem, not it.