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