Ajax instances compatible with earlier versions of IE

Source: Internet
Author: User

1 <!DOCTYPE HTML>2 <HTML>3 <HeadLang= "en">4     <MetaCharSet= "UTF-8">5     <title>Ajax</title>6 </Head>7 <Body>8 <Script>9     //Change the intranet security level to medium and low, add the website to the trusted site, change the security level of the trusted site to medium and low, and not be denied access in IE. Ten      One     //execute this statement as soon as the page has finished loading A window.onload= function () { - startrequest (); -     } the  -     //compatible with earlier versions of IE, set up a XMLHttpRequest object -     functioncreatexhr () { -         if (typeofXMLHttpRequest!= "undefined") { +             return NewXMLHttpRequest (); -         } Else if (typeofActiveXObject!= "undefined") { +             if (typeofarguments.callee.activeXString!= "string") { A                 varversions= ["msxml2.xmlhttp.6.0", "msxml2.xmlhttp.3.0", at                             "msxml2.xmlhttp"], - I, Len; -  -                  for(i= 0, Len=versions.length; I<Len; I++) { -                     Try { -                         NewActiveXObject (Versions[i]); in arguments.callee.activeXString=Versions[i]; -                          Break; to                     } Catch(ex) { +                         //can put the hint text -                     } the                 } *             } $ Panax Notoginseng             return NewActiveXObject (arguments.callee.activeXString); -         } Else { the             //no XHR object available, throwing an error +             Throw NewError ("No XHR object available."); A         } the     } +  -     //establishes a XHR object and sets the response method while detecting the return status $     functionstartrequest () { $          -         varXHR=createxhr (); -  the Xhr.onreadystatechange= function () { -             Wuyi             //ReadState indicates the current active state of the request or response process the             if(Xhr.readystate== 4) { -                 //Status Code 304 for the status response indicates that there is no change, and the browser's cache can be used Wu                 if(Xhr.status>=  $ &&Xhr.status<  - ||Xhr.status== 304) { - alert (xhr.responsetext); About                 } $                 Else { - Alert ("Failed to get the information!!!"); -                 } -             } A         } +         the          -         //three parameters, the requested method, the requested URL, whether the request is sent asynchronously $ Xhr.open ('Get', 'Data.txt', true); the Xhr.send (NULL); the     } the  the </Script> - </Body> in </HTML>


There should be a file called Data.txt in the sibling directory

The contents of the file can be customized and will appear in the warning box after successful operation

The blogger's file content is: Get the information successfully.

Ajax instances compatible with earlier versions of IE

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.