1. Proposed by: Jesse James Garrett
in 2.IE, XHR is implemented through ActiveX objects. relates to browser compatibility notation.
3. Use
<1>open ("Request Method", "Requested URL", "Synchronous or asynchronous")
<2>send ("Data sent as the request Principal") must pass in nullif it is not required.
<3>responsetext () is the text returned by the response body, and there is a responsexml
http status of the <4>status response
<5>statustext Description of HTTP status
4.readyStateThe onReadyStateChange event handler is triggered whenever readystate is changed from one value to another value.
to ensure compatibility, you should call onReadyStateChange before open. requests can also be canceled, using Xhr.abort ().
header information for 5.HTTP
6.GET Request
An error often occurs with get requests, which is that there is a problem with the format of the query string. The name and value of each parameter in the query string must be encoded with encodeuricomponent () before it can be placed at the end of the URL.
Blob object: is a binary object, slice, etc.
7.XMLHttpRequest Level 2
<1>formdatafacilitates the serialization of forms and the creation of the same data as form formats.
<2> Timeout SettingsRequest timed out execution callback: Xhr.timeout=function () {}
<3>overridemimetype ()overriding the MIME type of the XHR response
<4> Progress Events
<5>load Events
<6>progress Events
8. Example Demo:JS:
//Compatibility xhrfunctioncreatexhr () {if(typeofXMLHttpRequest! = "undefined"){ return NewXMLHttpRequest (); }Else if(typeofActiveXObject! = "undefined"){ if(typeofArguments.callee.activestring!= "string"){ varVersions=["MSXML2. XMLHTTP6.0 "," MSXML2. XMLHTTP3.0 "," MSXML2. XMLHTTP "], I,len; for(i=0;len=versions.lengthli<len;i++){ Try{ NewActiveXObject (Versions[i]); Arguments.callee.activeString=Versions[i]; Break; }Catch(ex) {//Skip over } } } return NewActiveXObject (arguments.callee.activeString); }Else{ Throw NewError ("No XHR available"); }}//compatibility notation var xhr=new createxhr ();varXhr=NewXMLHttpRequest (); Xhr.onreadystatechange=function(){ if(xhr.readystate==4){ if((xhr.status>=200 && xhr.status<300) | | xhr.status==304) {alert (xhr.responsetext); }Else{alert ("The request failed!" "); } } }; Xhr.open ("Get", "Zqz.txt",true); Xhr.send (NULL);
Results:
Request and Response information:After changing to POST request:
Xhrhttprequest in the Web