Xhrhttprequest in the Web

Source: Internet
Author: User

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

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.