Questions about browser compatibility in ajax synchronization mode-php Tutorial

Source: Internet
Author: User
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 Document

F

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.

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.