Annotation of 2006/webapi/XMLHttpRequest/Overview.html, revision 1.349

1.343     avankest    1: <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"><html lang="en-US"><head>
1.209     avankest    2:   <title>XMLHttpRequest</title>
1.20      avankest    3:   <style type="text/css">
1.118     avankest    4:    pre.idl { border:solid thin; background:#eee; color:#000; padding:0.5em }
1.20      avankest    5:    pre.idl :link, pre.idl :visited { color:inherit; background:transparent }
1.60      avankest    6:    pre code { color:inherit; background:transparent }
1.20      avankest    7:    div.example { margin-left:1em; padding-left:1em; border-left:double; color:#222; background:#fcfcfc }
1.90      avankest    8:    .note { margin-left:2em; font-weight:bold; font-style:italic; color:#008000 }
1.20      avankest    9:    p.note::before { content:"Note: " }
1.205     avankest   10:    .XXX { padding:.5em; border:solid #f00 }
                     11:    p.XXX::before { content:"Issue: " }
1.120     avankest   12:    dl.switch { padding-left:2em }
1.250     avankest   13:    dl.switch > dt { text-indent:-1.5em }
                     14:    dl.switch > dt:before { content:'\21AA'; padding:0 0.5em 0 0; display:inline-block; width:1em; text-align:right; line-height:0.5em }
1.274     avankest   15:    dl.domintro { color: green; margin: 2em 0 2em 2em; padding: 0.5em 1em; border: none; background: #DDFFDD; }
                     16:    dl.domintro dt, dl.domintro dt * { color: black; text-decoration: none; }
                     17:    dl.domintro dd { margin: 0.5em 0 1em 2em; padding: 0; }
                     18:    dl.domintro dd p { margin: 0.5em 0; }
                     19:    dl.domintro:before { display: table; margin: -1em -0.5em -0.5em auto; width: auto; content: 'This box is non-normative. Implementation requirements are given below this box.'; color: red; border: solid 2px; background: white; padding: 0 0.25em; }
1.232     avankest   20:    em.ct { text-transform:lowercase; font-variant:small-caps; font-style:normal }
                     21:    dfn { font-weight:bold; font-style:normal }
                     22:    code { color:orangered }
                     23:    code :link, code :visited { color:inherit }
                     24:    hr:not(.top) { display:block; background:none; border:none; padding:0; margin:2em 0; height:auto }
                     25:    table { border-collapse:collapse; border-style:hidden hidden none hidden }
                     26:    table thead { border-bottom:solid }
                     27:    table tbody th:first-child { border-left:solid }
                     28:    table td, table th { border-left:solid; border-right:solid; border-bottom:solid thin; vertical-align:top; padding:0.2em }
                     29:   </style>
1.343     avankest   30:   <link href="http://www.w3.org/StyleSheets/TR/W3C-ED" rel="stylesheet">
                     31:  </head>
                     32:  <body>
                     33:   <div class="head">
1.342     avankest   34: 
1.343     avankest   35: <!--begin-logo-->
                     36: <p><a href="http://www.w3.org/"><img alt="W3C" height="48" src="http://www.w3.org/Icons/w3c_home" width="72"></a></p>
                     37: <!--end-logo-->
1.342     avankest   38: 
1.343     avankest   39:    <h1 class="head" id="the-xmlhttprequest-object">XMLHttpRequest</h1>
                     40:    
1.342     avankest   41: 
1.349   ! avankest   42:    <h2 class="no-num no-toc" id="w3c-doctype">Editor's Draft 18 August 2011</h2>
1.342     avankest   43: 
                     44:    <dl>
1.343     avankest   45:     <dt>This Version:</dt>
                     46:     <dd class="dontpublish"><a href="http://dev.w3.org/2006/webapi/XMLHttpRequest/">http://dev.w3.org/2006/webapi/XMLHttpRequest/</a></dd>
                     47:     <dt>Previous Versions:</dt>
                     48:     
                     49:     <dd><a href="http://www.w3.org/TR/2010/CR-XMLHttpRequest-20100803/">http://www.w3.org/TR/2010/CR-XMLHttpRequest-20100803/</a></dd>
                     50:     <dd><a href="http://www.w3.org/TR/2009/WD-XMLHttpRequest-20091119/">http://www.w3.org/TR/2009/WD-XMLHttpRequest-20091119/</a></dd>
                     51:     <dd><a href="http://www.w3.org/TR/2009/WD-XMLHttpRequest-20090820/">http://www.w3.org/TR/2009/WD-XMLHttpRequest-20090820/</a></dd>
                     52:     <dd><a href="http://www.w3.org/TR/2008/WD-XMLHttpRequest-20080415/">http://www.w3.org/TR/2008/WD-XMLHttpRequest-20080415/</a></dd>
                     53:     <dd><a href="http://www.w3.org/TR/2007/WD-XMLHttpRequest-20071026/">http://www.w3.org/TR/2007/WD-XMLHttpRequest-20071026/</a></dd>
                     54:     <dd><a href="http://www.w3.org/TR/2007/WD-XMLHttpRequest-20070618/">http://www.w3.org/TR/2007/WD-XMLHttpRequest-20070618/</a></dd>
                     55:     <dd><a href="http://www.w3.org/TR/2007/WD-XMLHttpRequest-20070227/">http://www.w3.org/TR/2007/WD-XMLHttpRequest-20070227/</a></dd>
                     56:     <dd><a href="http://www.w3.org/TR/2006/WD-XMLHttpRequest-20060927/">http://www.w3.org/TR/2006/WD-XMLHttpRequest-20060927/</a></dd>
                     57:     <dd><a href="http://www.w3.org/TR/2006/WD-XMLHttpRequest-20060619/">http://www.w3.org/TR/2006/WD-XMLHttpRequest-20060619/</a></dd>
                     58:     <dd><a href="http://www.w3.org/TR/2006/WD-XMLHttpRequest-20060405/">http://www.w3.org/TR/2006/WD-XMLHttpRequest-20060405/</a></dd>
                     59:     
                     60:     
1.342     avankest   61: 
1.343     avankest   62:     <dt>Editor:</dt>
                     63:     <dd><a href="http://annevankesteren.nl/">Anne van Kesteren</a>
                     64:      (<a href="http://www.opera.com/">Opera Software ASA</a>)
                     65:      &lt;<a href="mailto:annevk@opera.com">annevk@opera.com</a>&gt;</dd>
                     66:    </dl>
1.342     avankest   67: 
                     68: 
1.343     avankest   69: <!--begin-copyright-->
                     70: <p class="copyright"><a href="http://www.w3.org/Consortium/Legal/ipr-notice#Copyright">Copyright</a> &copy; 2011 <a href="http://www.w3.org/"><abbr title="World Wide Web Consortium">W3C</abbr></a><sup>&reg;</sup> (<a href="http://www.csail.mit.edu/"><abbr title="Massachusetts Institute of Technology">MIT</abbr></a>, <a href="http://www.ercim.eu/"><abbr title="European Research Consortium for Informatics and Mathematics">ERCIM</abbr></a>, <a href="http://www.keio.ac.jp/">Keio</a>), All Rights Reserved. W3C <a href="http://www.w3.org/Consortium/Legal/ipr-notice#Legal_Disclaimer">liability</a>, <a href="http://www.w3.org/Consortium/Legal/ipr-notice#W3C_Trademarks">trademark</a> and <a href="http://www.w3.org/Consortium/Legal/copyright-documents">document use</a> rules apply.</p>
                     71: <!--end-copyright-->
                     72:   </div>
1.2       avankest   73: 
1.342     avankest   74:   <hr>
1.2       avankest   75: 
1.343     avankest   76:   <h2 class="no-num no-toc" id="specabstract">Abstract</h2>
1.25      avankest   77: 
1.343     avankest   78:   
                     79:   
                     80:   <p>The XMLHttpRequest specification defines an API
                     81:   that provides scripted client functionality for transferring data between
                     82:   a client and a server.</p>
                     83:   
                     84: 
                     85:   <h2 class="no-num no-toc" id="sotd">Status of this Document</h2>
                     86: 
                     87:   <p><em>This section describes the status of this document at the time of its
                     88:   publication. Other documents may supersede this document. A list of current
                     89:   W3C publications and the latest revision of this technical report can be
                     90:   found in the <a href="http://www.w3.org/TR/">W3C technical reports index</a>
                     91:   at http://www.w3.org/TR/.</em></p>
                     92: 
1.349   ! avankest   93:   <p>This is the 18 August 2011 Editor's Draft of
1.343     avankest   94:   XMLHttpRequest. Please send comments to
                     95:   <a href="mailto:public-webapps@w3.org?subject=[XHR]%20">public-webapps@w3.org</a>
                     96:   (<a href="http://lists.w3.org/Archives/Public/public-webapps/">archived</a>)
                     97:   with <samp>[XHR]</samp> at the start of the subject line.</p>
                     98: 
                     99:   
                    100:   <p>For the last Last Call Working Draft the Working Group has kept a
                    101:   <a href="http://dev.w3.org/2006/webapi/XMLHttpRequest/disposition-of-comments-3">disposition of comments</a>
                    102:   document. A
                    103:   <a href="http://dev.w3.org/cvsweb/2006/webapi/XMLHttpRequest/Overview.src.html">list of changes</a>
                    104:   is available via a Web view of CVS. (Due to the way the document is edited
                    105:   certain commit messages have introduced negligible changes to this
                    106:   document and are in fact only relevant for XMLHttpRequest Level 2.)</p>
                    107:   
                    108: 
                    109:   <p>This document is produced by the
                    110:   <a href="http://www.w3.org/2008/webapps/">Web Applications</a> (WebApps) Working Group.
                    111:   The WebApps Working Group is part of the
                    112:   <a href="http://www.w3.org/2006/rwc/Activity">Rich Web Clients Activity</a>
                    113:   in the W3C <a href="http://www.w3.org/Interaction/">Interaction Domain</a>.</p>
                    114: 
                    115:   <p>This document was produced by a group operating under the
                    116:   <a href="http://www.w3.org/Consortium/Patent-Policy-20040205/">5 February 2004
                    117:   W3C Patent Policy</a>. W3C maintains a
                    118:   <a href="http://www.w3.org/2004/01/pp-impl/42538/status" rel="disclosure">public
                    119:   list of any patent disclosures</a> made in connection with the deliverables of
                    120:   the group; that page also includes instructions for disclosing a patent. An
                    121:   individual who has actual knowledge of a patent which the individual believes
                    122:   contains
                    123:   <a href="http://www.w3.org/Consortium/Patent-Policy-20040205/#def-essential">Essential
                    124:   Claim(s)</a> must disclose the information in accordance with
                    125:   <a href="http://www.w3.org/Consortium/Patent-Policy-20040205/#sec-Disclosure">section
                    126:   6 of the W3C Patent Policy</a>.</p>
1.2       avankest  127: 
1.296     avankest  128:   <p>Publication as a Working Draft does not imply endorsement by the W3C
1.343     avankest  129:   Membership. This is a draft document and may be updated, replaced or
                    130:   obsoleted by other documents at any time. It is inappropriate to cite this
                    131:   document as other than work in progress.</p>
1.250     avankest  132: 
1.343     avankest  133:   
                    134:   <h3 class="no-num no-toc" id="crec">Candidate Recommendation Exit Criteria</h3>
1.273     avankest  135: 
                    136:   <p>To exit the Candidate Recommendation (CR) stage the following criteria
1.343     avankest  137:   must have been met:</p>
1.273     avankest  138: 
                    139:   <ol>
                    140:    <li>There will be at least two interoperable implementations passing all
1.343     avankest  141:    test cases in the
                    142:    <a href="http://test.w3.org/webapps/tests/XMLHttpRequest/info.htm">test suite</a>
                    143:    for this specification. An implementation is to be available (i.e. for
                    144:    download), shipping (i.e. not private), and not experimental (i.e.
                    145:    intended for a wide audience). The working group will decide when the
                    146:    test suite is of sufficient quality to test interoperability and will
                    147:    produce implementation reports (hosted together with the test suite).</li>
1.273     avankest  148: 
1.296     avankest  149:    <li>A minimum of six months of the CR stage will have elapsed. This is to
1.343     avankest  150:    ensure that enough time is given for any remaining major errors to be
                    151:    caught. The CR period will be extended if implementations are slow to
                    152:    appear.</li> <!-- XXX need to add date -->
1.287     avankest  153: 
1.288     avankest  154:    <li>Text, which can be in a separate document, exists that explains the
1.343     avankest  155:    security considerations for this specification. This may be done in a
                    156:    generic manner as they are most likely applicable to various APIs. The
                    157:    working group will decide whether the text is of sufficient quality.</li>
1.273     avankest  158:   </ol>
1.343     avankest  159:   
1.273     avankest  160: 
1.205     avankest  161: 
1.343     avankest  162:   <h2 class="no-num no-toc" id="toc">Table of Contents</h2>
1.205     avankest  163: 
1.343     avankest  164:   
                    165: <!--begin-toc-->
                    166: <ol class="toc">
                    167:  <li><a href="#introduction"><span class="secno">1 </span>Introduction</a></li>
                    168:  <li><a href="#conformance"><span class="secno">2 </span>Conformance</a>
                    169:   <ol class="toc">
                    170:    <li><a href="#dependencies"><span class="secno">2.1 </span>Dependencies</a></li>
                    171:    <li><a href="#extensibility"><span class="secno">2.2 </span>Extensibility</a></ol></li>
                    172:  <li><a href="#terminology"><span class="secno">3 </span>Terminology</a></li>
1.348     avankest  173:  <li><a href="#interface-xmlhttprequest"><span class="secno">4 </span>Interface <code title="">XMLHttpRequest</code></a>
1.343     avankest  174:   <ol class="toc">
1.348     avankest  175:    <li><a href="#origin-and-base-url"><span class="secno">4.1 </span>Origin and base URL</a></li>
                    176:    <li><a href="#task-sources"><span class="secno">4.2 </span>Task sources</a></li>
1.343     avankest  177:    <li><a href="#constructors"><span class="secno">4.3 </span>Constructors</a></li>
1.348     avankest  178:    <li><a href="#event-handlers"><span class="secno">4.4 </span>Event handlers</a></li>
1.343     avankest  179:    <li><a href="#states"><span class="secno">4.5 </span>States</a></li>
                    180:    <li><a href="#request"><span class="secno">4.6 </span>Request</a>
                    181:     <ol class="toc">
                    182:      <li><a href="#the-open-method"><span class="secno">4.6.1 </span>The <code title="">open()</code> method</a></li>
                    183:      <li><a href="#the-setrequestheader-method"><span class="secno">4.6.2 </span>The <code title="">setRequestHeader()</code> method</a></li>
                    184:      <li><a href="#the-send-method"><span class="secno">4.6.3 </span>The <code title="">send()</code> method</a></li>
                    185:      <li><a href="#infrastructure-for-the-send-method"><span class="secno">4.6.4 </span>Infrastructure for the <code title="">send()</code> method</a></li>
                    186:      <li><a href="#the-abort-method"><span class="secno">4.6.5 </span>The <code title="">abort()</code> method</a></ol></li>
                    187:    <li><a href="#response"><span class="secno">4.7 </span>Response</a>
                    188:     <ol class="toc">
                    189:      <li><a href="#the-status-attribute"><span class="secno">4.7.1 </span>The <code title="">status</code> attribute</a></li>
                    190:      <li><a href="#the-statustext-attribute"><span class="secno">4.7.2 </span>The <code title="">statusText</code> attribute</a></li>
                    191:      <li><a href="#the-getresponseheader-method"><span class="secno">4.7.3 </span>The <code title="">getResponseHeader()</code> method</a></li>
                    192:      <li><a href="#the-getallresponseheaders-method"><span class="secno">4.7.4 </span>The <code title="">getAllResponseHeaders()</code> method</a></li>
1.348     avankest  193:      <li><a href="#response-entity-body-0"><span class="secno">4.7.5 </span>Response entity body</a></li>
1.343     avankest  194:      <li><a href="#the-responsetext-attribute"><span class="secno">4.7.6 </span>The <code title="">responseText</code> attribute</a></li>
                    195:      <li><a href="#the-responsexml-attribute"><span class="secno">4.7.7 </span>The <code title="">responseXML</code> attribute</a></ol></ol></li>
                    196:  <li><a class="no-num" href="#references">References</a>
                    197:   <ol class="toc">
                    198:    <li><a class="no-num" href="#normative-references">Normative references</a></li>
                    199:    <li><a class="no-num" href="#informative-references">Informative references</a></ol></li>
                    200:  <li><a class="no-num" href="#acknowledgments">Acknowledgments</a></ol>
                    201: <!--end-toc-->
                    202: 
                    203: 
                    204: 
                    205:   <h2 id="introduction"><span class="secno">1 </span>Introduction</h2>
                    206: 
                    207:   <p><em>This section is non-normative.</em></p>
                    208: 
                    209:   <p>The <code><a href="#xmlhttprequest">XMLHttpRequest</a></code> object implements an interface exposed
                    210:   by a scripting engine that allows scripts to perform HTTP client
                    211:   functionality, such as submitting form data or loading data from a
                    212:   server. It is the ECMAScript HTTP API.
                    213:   <a class="informative" href="#refsECMASCRIPT">[ECMASCRIPT]</a>
                    214: 
                    215:   <p>The name of the object is <code><a href="#xmlhttprequest">XMLHttpRequest</a></code> for compatibility
                    216:   with the Web, though each component of this name is potentially
                    217:   misleading. First, the object supports any text based format, including
                    218:   XML. Second, it can be used to make requests over both HTTP and HTTPS
                    219:   (some implementations support protocols in addition to HTTP and HTTPS, but
                    220:   that functionality is not covered by this specification). Finally, it
                    221:   supports "requests" in a broad sense of the term as it pertains to HTTP;
                    222:   namely all activity involved with HTTP requests or responses for the
                    223:   defined HTTP methods.</p>
                    224: 
                    225:   <div class="example">
                    226:    <p>Some simple code to do something with data from an XML document
                    227:    fetched over the network:</p>
1.18      avankest  228: 
1.312     avankest  229:    <pre><code>function processData(data) {
1.316     avankest  230:   // taking care of data
1.18      avankest  231: }
                    232: 
                    233: function handler() {
1.316     avankest  234:   if(this.readyState == this.DONE) {
                    235:     if(this.status == 200 &amp;&amp;
                    236:        this.responseXML != null &amp;&amp;
                    237:        this.responseXML.getElementById('test').textContent) {
1.312     avankest  238:       // success!
                    239:       processData(this.responseXML.getElementById('test').textContent);
                    240:       return;
                    241:     }
1.316     avankest  242:     // something went wrong
                    243:     processData(null);
1.312     avankest  244:   }
1.18      avankest  245: }
                    246: 
                    247: var client = new XMLHttpRequest();
                    248: client.onreadystatechange = handler;
1.252     avankest  249: client.open("GET", "unicorn.xml");
1.60      avankest  250: client.send();</code></pre>
1.18      avankest  251: 
1.58      avankest  252:    <p>If you just want to log a message to the server:</p>
1.18      avankest  253: 
1.60      avankest  254:    <pre><code>function log(message) {
1.312     avankest  255:   var client = new XMLHttpRequest();
                    256:   client.open("POST", "/log");
                    257:   client.setRequestHeader("Content-Type", "text/plain;charset=UTF-8");
                    258:   client.send(message);
1.60      avankest  259: }</code></pre>
1.18      avankest  260: 
                    261:    <p>Or if you want to check the status of a document on the server:</p>
                    262: 
1.60      avankest  263:    <pre><code>function fetchStatus(address) {
1.312     avankest  264:   var client = new XMLHttpRequest();
                    265:   client.onreadystatechange = function() {
                    266:     // in case of network errors this might not give reliable results
1.314     avankest  267:     if(this.readyState == this.DONE)
1.312     avankest  268:       returnStatus(this.status);
                    269:   }
                    270:   client.open("HEAD", address);
                    271:   client.send();
1.60      avankest  272: }</code></pre>
1.18      avankest  273:   </div>
1.2       avankest  274: 
1.343     avankest  275: 
                    276: 
                    277: 
                    278:   <h2 id="conformance"><span class="secno">2 </span>Conformance</h2>
1.2       avankest  279: 
1.29      avankest  280:   <p>Everything in this specification is normative except for diagrams,
1.343     avankest  281:   examples, notes and sections marked non-normative.</p>
1.2       avankest  282: 
1.341     avankest  283:   <p>The key words must, must not, should, should not and may in this
1.343     avankest  284:   document are to be interpreted as described in RFC 2119.
                    285:   <a href="#refsRFC2119">[RFC2119]</a></p>
1.2       avankest  286: 
1.343     avankest  287:   <p>This specification defines a single conformance class:</p>
1.2       avankest  288: 
                    289:   <dl>
1.343     avankest  290:    <dt><dfn id="conforming-user-agent">Conforming user agent</dfn></dt>
1.2       avankest  291: 
1.75      avankest  292:    <dd>
1.343     avankest  293:     <p>A user agent must behave as described in this
                    294:     specification in order to be considered conformant.</p>
1.75      avankest  295: 
1.343     avankest  296:     <p>User agents may implement algorithms given in
                    297:     this specification in any way desired, so long as the end result is
                    298:     indistinguishable from the result that would be obtained by the
                    299:     specification's algorithms.</p>
1.2       avankest  300: 
1.343     avankest  301:     <p class="note">This specification uses both the terms "conforming user
                    302:     agent(s)" and "user agent(s)" to refer to this product class.</p>
                    303:    </dd>
1.2       avankest  304:   </dl>
                    305: 
1.343     avankest  306:   <h3 id="dependencies"><span class="secno">2.1 </span>Dependencies</h3>
1.2       avankest  307: 
1.343     avankest  308:   <p>This specification relies on several underlying specifications.</p>
1.2       avankest  309: 
1.31      avankest  310:   <dl>
1.343     avankest  311:    
1.341     avankest  312: 
1.343     avankest  313:    <dt>DOM Core</dt>
                    314:    <dd><p>A <a href="#conforming-user-agent">conforming user agent</a> must
                    315:    support at least the subset of the functionality defined in DOM Core that
                    316:    this specification relies upon, such as various exceptions and
                    317:    <code class="external"><a href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#eventtarget">EventTarget</a></code>. <a href="#refsDOMCORE">[DOMCORE]</a></dd>
                    318: 
                    319:    <dt>File API</dt>
                    320:    <dd><p>A <a href="#conforming-user-agent">conforming user agent</a> must
                    321:    support at least the subset of the functionality defined in File API that
                    322:    this specification relies upon, such as the <code class="external"><a href="http://dev.w3.org/2006/webapi/FileAPI/#blob">Blob</a></code> and
                    323:    <code class="external"><a href="http://dev.w3.org/2006/webapi/FileAPI/#file">File</a></code> interfaces. <a href="#refsFILEAPI">[FILEAPI]</a></p>
                    324:    
                    325: 
                    326:    <dt>HTML</dt>
                    327:    <dd><p>A <a href="#conforming-user-agent">conforming user agent</a> must
                    328:    support at least the subset of the functionality defined in HTML that
                    329:    this specification relies upon, such as the basics of the
1.346     avankest  330:    <code class="external"><a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/browsers.html#window">Window</a></code> object and serializing a <code class="external"><a href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#document">Document</a></code>
1.343     avankest  331:    object. <a href="#refsHTML">[HTML]</a>
                    332: 
                    333:    <dt>HTTP</dt>
                    334:    <dd><p>A <a href="#conforming-user-agent">conforming user agent</a> must
                    335:    support some version of the HTTP protocol. Requirements regarding HTTP
                    336:    are made throughout the specification. <a href="#refsHTTP">[HTTP]</a>
                    337: 
                    338:    
                    339: 
                    340:    <dt>Web IDL</dt>
                    341:    <dd><p>A <a href="#conforming-user-agent">conforming user agent</a> must also
                    342:    be a conforming implementation of the IDL fragments in this
                    343:    specification, as described in the Web IDL specification.
                    344:    <a href="#refsWEBIDL">[WEBIDL]</a>
                    345: 
                    346:    <dt>XML</dt>
                    347:    <dd><p>A <a href="#conforming-user-agent">conforming user agent</a> must be a
                    348:    conforming XML processor that reports violations of namespace
                    349:    well-formedness. <a href="#refsXML">[XML]</a>
                    350:    <a href="#refsXMLNS">[XMLNS]</a>
                    351:   </dl>
1.2       avankest  352: 
                    353: 
1.343     avankest  354:   <h3 id="extensibility"><span class="secno">2.2 </span>Extensibility</h3>
1.162     avankest  355: 
1.343     avankest  356:   <p>User agents, Working Groups, and other interested parties are
                    357:   <em>strongly encouraged</em> to discuss extensions on a relevant public
                    358:   forum, preferably
                    359:   <a href="mailto:public-webapps@w3.org">public-webapps@w3.org</a>. If this
                    360:   is for some reason not possible prefix the extension in some way and start
                    361:   the prefix with an uppercase letter. E.g. if company Foo wants to add a
                    362:   private method <code>bar()</code> it could be named <code>FooBar()</code>
                    363:   to prevent clashes with a potential future standardized
                    364:   <code>bar()</code>.</p>
1.162     avankest  365: 
1.11      avankest  366: 
1.182     avankest  367: 
1.343     avankest  368:   <h2 id="terminology"><span class="secno">3 </span>Terminology</h2>
1.182     avankest  369: 
1.343     avankest  370:   
1.304     avankest  371: 
1.343     avankest  372:   <p>To <dfn id="deflate-a-domstring-into-a-byte-sequence">deflate a DOMString into a byte sequence</dfn> means to create
                    373:   a sequence of bytes such that the <var title="">n</var>th byte of the
                    374:   sequence is equal to the low-order byte of the <var title="">n</var>th
                    375:   code point in the original DOMString.</p>
1.304     avankest  376: 
1.343     avankest  377:   <p>To <dfn id="inflate-a-byte-sequence-into-a-domstring">inflate a byte sequence into a DOMString</dfn> means to create
                    378:   a DOMString such that the <var title="">n</var>th code point has 0x00 as
                    379:   the high-order byte and the <var title="">n</var>th byte of the byte
                    380:   sequence as the low-order byte.</p>
1.2       avankest  381: 
1.332     avankest  382: 
1.205     avankest  383: 
1.348     avankest  384:   <h2 id="interface-xmlhttprequest"><span class="secno">4 </span>Interface <code title="">XMLHttpRequest</code></h2>
1.2       avankest  385: 
1.343     avankest  386:   <p>The <code><a href="#xmlhttprequest">XMLHttpRequest</a></code> object can be used by scripts to issue
                    387:   HTTP requests.</p>
1.2       avankest  388: 
1.343     avankest  389:   <pre class="idl">[NoInterfaceObject]
                    390: interface <dfn id="xmlhttprequesteventtarget">XMLHttpRequestEventTarget</dfn> : <a class="external" href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#eventtarget">EventTarget</a> {
1.230     avankest  391:   // for future use
                    392: };
                    393: 
1.343     avankest  394: [<a href="#dom-xmlhttprequest" title="dom-XMLHttpRequest">Constructor</a>]
                    395: interface <dfn id="xmlhttprequest">XMLHttpRequest</dfn> : <a href="#xmlhttprequesteventtarget">XMLHttpRequestEventTarget</a> {
1.341     avankest  396:   // <a href="#event-handlers">event handler</a>
1.346     avankest  397:            attribute <a class="external" href="http://www.whatwg.org/specs/web-apps/current-work/multipage/webappapis.html#function">Function</a> <a href="#handler-xhr-onreadystatechange" title="handler-xhr-onreadystatechange">onreadystatechange</a>;
1.60      avankest  398: 
1.208     avankest  399:   // <a href="#states">states</a>
1.343     avankest  400:   const unsigned short <a href="#dom-xmlhttprequest-unsent" title="dom-XMLHttpRequest-UNSENT">UNSENT</a> = 0;
                    401:   const unsigned short <a href="#dom-xmlhttprequest-opened" title="dom-XMLHttpRequest-OPENED">OPENED</a> = 1;
1.277     avankest  402:   const unsigned short <a href="#dom-xmlhttprequest-headers_received" title="dom-XMLHttpRequest-HEADERS_RECEIVED">HEADERS_RECEIVED</a> = 2;
1.343     avankest  403:   const unsigned short <a href="#dom-xmlhttprequest-loading" title="dom-XMLHttpRequest-LOADING">LOADING</a> = 3;
                    404:   const unsigned short <a href="#dom-xmlhttprequest-done" title="dom-XMLHttpRequest-DONE">DONE</a> = 4;
                    405:   readonly attribute unsigned short <a href="#dom-xmlhttprequest-readystate" title="dom-XMLHttpRequest-readyState">readyState</a>;
1.60      avankest  406: 
1.207     avankest  407:   // <a href="#request">request</a>
1.343     avankest  408:   void <a href="#dom-xmlhttprequest-open" title="dom-XMLHttpRequest-open">open</a>(DOMString <var>method</var>, DOMString <var title="">url</var>);
                    409:   void <a href="#dom-xmlhttprequest-open" title="dom-XMLHttpRequest-open">open</a>(DOMString <var>method</var>, DOMString <var title="">url</var>, boolean <var>async</var>);
                    410:   void <a href="#dom-xmlhttprequest-open" title="dom-XMLHttpRequest-open">open</a>(DOMString <var>method</var>, DOMString <var title="">url</var>, boolean <var>async</var>, DOMString? <var>user</var>);
                    411:   void <a href="#dom-xmlhttprequest-open" title="dom-XMLHttpRequest-open">open</a>(DOMString <var>method</var>, DOMString <var title="">url</var>, boolean <var>async</var>, DOMString? <var>user</var>, DOMString? <var>password</var>);
                    412:   void <a href="#dom-xmlhttprequest-setrequestheader" title="dom-XMLHttpRequest-setRequestHeader">setRequestHeader</a>(DOMString <var>header</var>, DOMString <var>value</var>);
                    413:   void <a href="#dom-xmlhttprequest-send" title="dom-XMLHttpRequest-send">send</a>();
                    414:   void <a href="#dom-xmlhttprequest-send" title="dom-XMLHttpRequest-send">send</a>(<a class="external" href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#document">Document</a> <var>data</var>);
                    415:   void <a href="#dom-xmlhttprequest-send" title="dom-XMLHttpRequest-send">send</a>([AllowAny] DOMString? <var>data</var>);
                    416:   void <a href="#dom-xmlhttprequest-abort" title="dom-XMLHttpRequest-abort">abort</a>();
1.60      avankest  417: 
1.207     avankest  418:   // <a href="#response">response</a>
1.343     avankest  419:   readonly attribute unsigned short <a href="#dom-xmlhttprequest-status" title="dom-XMLHttpRequest-status">status</a>;
                    420:   readonly attribute DOMString <a href="#dom-xmlhttprequest-statustext" title="dom-XMLHttpRequest-statusText">statusText</a>;
                    421:   DOMString <a href="#dom-xmlhttprequest-getresponseheader" title="dom-XMLHttpRequest-getResponseHeader">getResponseHeader</a>(DOMString <var>header</var>);
                    422:   DOMString <a href="#dom-xmlhttprequest-getallresponseheaders" title="dom-XMLHttpRequest-getAllResponseHeaders">getAllResponseHeaders</a>();
                    423:   readonly attribute DOMString <a href="#dom-xmlhttprequest-responsetext" title="dom-XMLHttpRequest-responseText">responseText</a>;
                    424:   readonly attribute <span>Document</span> <a href="#dom-xmlhttprequest-responsexml" title="dom-XMLHttpRequest-responseXML">responseXML</a>;
1.230     avankest  425: };</pre>
1.2       avankest  426: 
1.205     avankest  427: 
1.275     avankest  428: 
1.348     avankest  429:   <h3 id="origin-and-base-url"><span class="secno">4.1 </span>Origin and base URL</h3>
1.342     avankest  430: 
1.343     avankest  431:   <p>Each <code><a href="#xmlhttprequest">XMLHttpRequest</a></code> object has an associated
1.345     avankest  432:   <dfn id="xmlhttprequest-origin"><code>XMLHttpRequest</code> origin</dfn> and an
1.343     avankest  433:   <dfn id="xmlhttprequest-base-url"><code>XMLHttpRequest</code> base URL</dfn>.
1.275     avankest  434: 
1.343     avankest  435:   <p>This specification defines their values when the global object is
1.346     avankest  436:   represented by the <code class="external"><a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/browsers.html#window">Window</a></code> object. When
1.345     avankest  437:   the <code><a href="#xmlhttprequest">XMLHttpRequest</a></code> object is used in other contexts their
                    438:   values will have to be defined as appropriate for that context. That is
1.343     avankest  439:   considered to be out of scope for this specification.</p>
1.207     avankest  440: 
1.343     avankest  441:   <p>In environments where the global object is represented by the
1.346     avankest  442:   <code class="external"><a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/browsers.html#window">Window</a></code> object the
1.345     avankest  443:   <code><a href="#xmlhttprequest">XMLHttpRequest</a></code> object has an associated
1.349   ! avankest  444:   <dfn id="xmlhttprequest-document"><code>XMLHttpRequest</code> document</dfn> which is the
        !           445:   <a class="external" href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-document" title="concept-document">document</a>
        !           446:   associated with the <code class="external"><a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/browsers.html#window">Window</a></code> object for
        !           447:   which the <code><a href="#xmlhttprequest">XMLHttpRequest</a></code> interface object was created.</p>
1.207     avankest  448: 
1.343     avankest  449:   <p class="note">The
1.349   ! avankest  450:   <a href="#xmlhttprequest-document"><code>XMLHttpRequest</code> document</a> is used to
1.343     avankest  451:   determine the <a href="#xmlhttprequest-origin"><code>XMLHttpRequest</code> origin</a> and
                    452:   <a href="#xmlhttprequest-base-url"><code>XMLHttpRequest</code> base URL</a> at a later stage.</p>
1.207     avankest  453: 
                    454: 
                    455: 
1.348     avankest  456:   <h3 id="task-sources"><span class="secno">4.2 </span>Task sources</h3>
1.205     avankest  457: 
1.346     avankest  458:   <p>The <a class="external" href="http://www.whatwg.org/specs/web-apps/current-work/multipage/webappapis.html#task-source">task source</a> used by this
1.343     avankest  459:   specification is the <dfn id="xmlhttprequest-task-source"><code>XMLHttpRequest</code> task source</dfn>.
1.282     avankest  460: 
                    461: 
1.343     avankest  462:   <h3 id="constructors"><span class="secno">4.3 </span>Constructors</h3>
1.205     avankest  463: 
1.343     avankest  464:   
1.125     avankest  465: 
1.343     avankest  466:   <dl class="domintro">
                    467:    <dt><var title="">client</var> = new <code title="dom-XMLHttpRequest"><a href="#dom-xmlhttprequest">XMLHttpRequest</a></code>()</dt>
                    468:    <dd>Returns a new <code><a href="#xmlhttprequest">XMLHttpRequest</a></code> object.</dd>
                    469:    
                    470:   </dl>
1.205     avankest  471: 
1.343     avankest  472:   <p>When the
                    473:   <dfn id="dom-xmlhttprequest" title="dom-XMLHttpRequest"><code>XMLHttpRequest()</code></dfn>
1.345     avankest  474:   constructor is invoked, the user agent must return a new
                    475:   <code><a href="#xmlhttprequest">XMLHttpRequest</a></code> object.</p>
1.343     avankest  476: 
                    477:   
                    478: 
1.348     avankest  479:   <h3 id="event-handlers"><span class="secno">4.4 </span>Event handlers</h3>
1.343     avankest  480: 
                    481:   
                    482: 
                    483:   <p>The following is the
1.346     avankest  484:   <a class="external" href="http://www.whatwg.org/specs/web-apps/current-work/multipage/webappapis.html#event-handlers" title="event handlers">event handler</a>
1.345     avankest  485:   (and its corresponding
1.346     avankest  486:   <a class="external" href="http://www.whatwg.org/specs/web-apps/current-work/multipage/webappapis.html#event-handler-event-type">event handler event type</a>) that must be
1.345     avankest  487:   supported as attribute by the
1.343     avankest  488:   <code><a href="#xmlhttprequest">XMLHttpRequest</a></code> object:</p>
1.205     avankest  489: 
1.343     avankest  490:   <table>
                    491:    <thead>
                    492:     <tr>
1.346     avankest  493:      <th><a class="external" href="http://www.whatwg.org/specs/web-apps/current-work/multipage/webappapis.html#event-handlers" title="event handlers">event handler</a>
                    494:      <th><a class="external" href="http://www.whatwg.org/specs/web-apps/current-work/multipage/webappapis.html#event-handler-event-type">event handler event type</a>
1.343     avankest  495:    <tbody>
                    496:     <tr>
                    497:      <td><dfn id="handler-xhr-onreadystatechange" title="handler-xhr-onreadystatechange"><code>onreadystatechange</code></dfn>
                    498:      <td><code title="event-xhr-readystatechange">readystatechange</code></td>
                    499:   </table>
1.89      avankest  500: 
1.112     avankest  501: 
1.343     avankest  502:   <h3 id="states"><span class="secno">4.5 </span>States</h3>
1.91      avankest  503: 
1.343     avankest  504:   <dl class="domintro">
                    505:    <dt><var title="">client</var> . <code title="dom-XMLHttpRequest-readyState"><a href="#dom-xmlhttprequest-readystate">readyState</a></code></dt>
                    506:    <dd><p>Returns the current state.</dd>
1.205     avankest  507:   </dl>
1.116     avankest  508: 
1.343     avankest  509:   <p>The <code><a href="#xmlhttprequest">XMLHttpRequest</a></code> object can be in several states. The
                    510:   <dfn id="dom-xmlhttprequest-readystate" title="dom-XMLHttpRequest-readyState"><code>readyState</code></dfn>
1.345     avankest  511:   attribute must return the current state, which must be one of the
                    512:   following values:</p>
1.112     avankest  513: 
1.206     avankest  514:   <dl>
1.343     avankest  515:    <dt><dfn id="dom-xmlhttprequest-unsent" title="dom-XMLHttpRequest-UNSENT"><code>UNSENT</code></dfn>
                    516:    (numeric value 0)</dt>
                    517:    <dd><p>The object has been constructed.</dd>
                    518: 
                    519:    <dt><dfn id="dom-xmlhttprequest-opened" title="dom-XMLHttpRequest-OPENED"><code>OPENED</code></dfn>
                    520:    (numeric value 1)</dt>
                    521:    <dd><p>The <code title="dom-XMLHttpRequest-open"><a href="#dom-xmlhttprequest-open">open()</a></code> method has been successfully invoked.
                    522:    During this state request headers can be set using
                    523:    <code title="dom-XMLHttpRequest-setRequestHeader"><a href="#dom-xmlhttprequest-setrequestheader">setRequestHeader()</a></code>
                    524:    and the request can be made using the
                    525:    <code title="dom-XMLHttpRequest-send"><a href="#dom-xmlhttprequest-send">send()</a></code> method.</dd>
                    526: 
                    527:    <dt><dfn id="dom-xmlhttprequest-headers_received" title="dom-XMLHttpRequest-HEADERS_RECEIVED"><code>HEADERS_RECEIVED</code></dfn>
                    528:    (numeric value 2)</dt>
                    529:    <dd><p>All redirects (if any) have been followed and all HTTP headers of
                    530:    the final response have been received. Several response members of the
                    531:    object are now available.</dd>
                    532: 
                    533:    <dt><dfn id="dom-xmlhttprequest-loading" title="dom-XMLHttpRequest-LOADING"><code>LOADING</code></dfn>
                    534:    (numeric value 3)</dt>
                    535:    <dd><p>The <a href="#response-entity-body">response entity body</a> is being received.</dd>
                    536: 
                    537:    <dt><dfn id="dom-xmlhttprequest-done" title="dom-XMLHttpRequest-DONE"><code>DONE</code></dfn>
                    538:    (numeric value 4)</dt>
                    539:    <dd><p>The data transfer has been completed or something went wrong
                    540:    during the transfer (e.g. infinite redirects).</dd>
                    541:   </dl>
1.342     avankest  542: 
1.343     avankest  543:   <p>The <a href="#dom-xmlhttprequest-opened" title="dom-XMLHttpRequest-OPENED">OPENED</a> state has an associated
                    544:   <dfn id="send-flag"><code>send()</code> flag</dfn> that indicates whether
                    545:   the <code title="dom-XMLHttpRequest-send"><a href="#dom-xmlhttprequest-send">send()</a></code> method has been
                    546:   invoked. It can be either true or false and has an initial value of
                    547:   false.</p>
                    548: 
                    549:   <p>The <dfn id="error-flag">error flag</dfn> indicates some type of
                    550:   network error or abortion. It is used during the
                    551:   <a href="#dom-xmlhttprequest-done" title="dom-XMLHttpRequest-DONE">DONE</a> state. It can be either
                    552:   true or false and has an initial value of false.</p>
1.342     avankest  553: 
                    554: 
1.343     avankest  555:   <h3 id="request"><span class="secno">4.6 </span>Request</h3>
1.342     avankest  556: 
1.343     avankest  557:   <p>The <code><a href="#xmlhttprequest">XMLHttpRequest</a></code> object holds the following request
                    558:   metadata variables:</p>
1.342     avankest  559: 
1.343     avankest  560:   <dl>
                    561:    <dt>The <dfn id="asynchronous-flag">asynchronous flag</dfn></dt>
1.346     avankest  562:    <dd>True when <a class="external" href="http://www.whatwg.org/specs/web-apps/current-work/multipage/urls.html#fetch" title="fetch">fetching</a> is
1.345     avankest  563:    done asychronously. False when fetching is done synchronously.</dd>
1.343     avankest  564: 
                    565:    <dt>The <dfn id="request-method">request method</dfn></dt>
                    566:    <dd>The HTTP method used in the request.</dd>
                    567: 
                    568:    <dt>The <dfn id="request-url">request URL</dfn></dt>
1.346     avankest  569:    <dd>The resolved <a class="external" href="http://www.whatwg.org/specs/web-apps/current-work/multipage/urls.html#url">URL</a> used in the
1.343     avankest  570:    request.</dd>
                    571: 
                    572:    <dt>The <dfn id="request-username">request username</dfn></dt>
                    573:    <dd>The username used in the request or null if there is no
                    574:    username.</dd>
                    575: 
                    576:    <dt>The <dfn id="request-password">request password</dfn></dt>
                    577:    <dd>The password used in the request or null if there is no
                    578:    password.</dd>
1.206     avankest  579: 
1.343     avankest  580:    <dt>The <dfn id="author-request-headers">author request headers</dfn></dt>
                    581:    <dd>A list consisting of HTTP header name/value pairs to be used in the
                    582:    request.<p></p>
1.206     avankest  583: 
1.343     avankest  584:    <dt>The <dfn id="request-entity-body">request entity body</dfn></dt>
                    585:    <dd>The <a class="external" href="http://tools.ietf.org/html/rfc2616/#section-7.2">entity body</a> used in the
                    586:    request or null if there is no
                    587:    <a class="external" href="http://tools.ietf.org/html/rfc2616/#section-7.2">entity body</a>.</dd>
1.206     avankest  588: 
1.343     avankest  589:    
                    590:   </dl>
1.206     avankest  591: 
1.343     avankest  592:   
1.206     avankest  593: 
                    594: 
1.343     avankest  595:   <h4 id="the-open-method"><span class="secno">4.6.1 </span>The <code title="">open()</code> method</h4>
1.206     avankest  596: 
1.343     avankest  597:   <dl class="domintro">
                    598:    <dt><var title="">client</var> . <code title="dom-XMLHttpRequest-open"><a href="#dom-xmlhttprequest-open">open(<var title="">method</var>,
                    599:    <var title="">url</var>, <var title="">async</var>, <var title="">user</var>,
                    600:    <var title="">password</var>)</a></code></dt>
1.206     avankest  601: 
1.343     avankest  602:    <dd>
                    603:     <p>Sets the <a href="#request-method">request method</a>, <a href="#request-url">request URL</a>,
                    604:     <a href="#asynchronous-flag">asynchronous flag</a>, <a href="#request-username">request username</a>, and
                    605:     <a href="#request-password">request password</a>.</p>
1.206     avankest  606: 
1.343     avankest  607:     <p>Throws a <code class="external" title="dom-DOMException-SYNTAX_ERR"><a href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#dom-domexception-syntax_err">SYNTAX_ERR</a></code> exception if one of the following is
                    608:     true:</p>
1.112     avankest  609: 
1.342     avankest  610:     <ul>
1.343     avankest  611:      <li><var title="">method</var> is not a valid HTTP method.</li>
                    612:      <li><var title="">url</var> cannot be resolved.</li>
                    613:      <li><var title="">url</var> contains the <code>"user:password"</code>
                    614:      format in the <code class="external"><a href="http://tools.ietf.org/html/rfc2616/#section-3.2.1">userinfo</a></code> production.
1.285     avankest  615:     </ul>
                    616: 
1.343     avankest  617:     <p>Throws a <code class="external" title="dom-DOMException-SECURITY_ERR"><a href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#dom-domexception-security_err">SECURITY_ERR</a></code> exception if
                    618:     <var title="">method</var> is a case-insensitive match for
                    619:     <code>CONNECT</code>, <code>TRACE</code> or <code>TRACK</code>.</p>
                    620: 
                    621:     <p>Throws an <code class="external" title="dom-DOMException-INVALID_ACCESS_ERR"><a href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#dom-domexception-invalid_access_err">INVALID_ACCESS_ERR</a></code> exception if either
                    622:     <var title="">user</var> or <var title="">password</var> is passed as
1.346     avankest  623:     argument and the <a class="external" href="http://www.whatwg.org/specs/web-apps/current-work/multipage/origin-0.html#origin">origin</a> of <var title="">url</var> does not
1.343     avankest  624:     match the <a href="#xmlhttprequest-origin"><code>XMLHttpRequest</code> origin</a>.</p>
                    625:    </dd>
1.274     avankest  626:   </dl>
                    627: 
1.343     avankest  628:   <p>When the
                    629:   <dfn id="dom-xmlhttprequest-open" title="dom-XMLHttpRequest-open"><code>open(<var title="">method</var>, <var title="">url</var>, <var title="">async</var>, <var title="">user</var>, <var title="">password</var>)</code></dfn>
                    630:   method is invoked, the user agent must run these steps
                    631:   (unless otherwise indicated):</p>
1.112     avankest  632: 
1.205     avankest  633:   <ol>
                    634:    <li>
1.343     avankest  635:     <p>If the <code><a href="#xmlhttprequest">XMLHttpRequest</a></code> object has an associated
1.349   ! avankest  636:     <a href="#xmlhttprequest-document"><code>XMLHttpRequest</code> document</a> run
1.343     avankest  637:     these substeps:</p>
1.112     avankest  638: 
1.205     avankest  639:     <ol>
1.343     avankest  640:      <li><p>If the
1.349   ! avankest  641:      <a href="#xmlhttprequest-document"><code>XMLHttpRequest</code> document</a> is not
1.346     avankest  642:      <a class="external" href="http://www.whatwg.org/specs/web-apps/current-work/multipage/browsers.html#fully-active">fully active</a> raise an
1.343     avankest  643:      <code class="external" title="dom-DOMException-INVALID_STATE_ERR"><a href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#dom-domexception-invalid_state_err">INVALID_STATE_ERR</a></code>
                    644:      exception and terminate the overall set of steps.</li>
                    645: 
                    646:      <li><p>Let <a href="#xmlhttprequest-base-url"><code>XMLHttpRequest</code> base URL</a> be the
1.346     avankest  647:      <a class="external" href="http://www.whatwg.org/specs/web-apps/current-work/multipage/urls.html#document-base-url">document base URL</a> of the
1.349   ! avankest  648:      <a href="#xmlhttprequest-document"><code>XMLHttpRequest</code> document</a>.</li>
1.343     avankest  649: 
                    650:      <li><p>Let <a href="#xmlhttprequest-origin"><code>XMLHttpRequest</code> origin</a> be the
1.346     avankest  651:      <a class="external" href="http://www.whatwg.org/specs/web-apps/current-work/multipage/origin-0.html#origin">origin</a> of the
1.349   ! avankest  652:      <a href="#xmlhttprequest-document"><code>XMLHttpRequest</code> document</a>.</li>
1.205     avankest  653:     </ol>
1.343     avankest  654:    </li>
1.342     avankest  655: 
1.343     avankest  656:    <li><p>If any code point in <var>method</var> is higher than
                    657:    U+00FF LATIN SMALL LETTER Y WITH DIAERESIS or after
                    658:    <a href="#deflate-a-domstring-into-a-byte-sequence" title="deflate a DOMString into a byte sequence">deflating</a>
                    659:    <var>method</var> it does not match the
                    660:    <a class="external" href="http://tools.ietf.org/html/rfc2616/#section-5.1.1">Method</a> token production raise a <code class="external" title="dom-DOMException-SYNTAX_ERR"><a href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#dom-domexception-syntax_err">SYNTAX_ERR</a></code>
                    661:    exception and terminate these steps. Otherwise let <var>method</var> be
                    662:    the result of
                    663:    <a href="#deflate-a-domstring-into-a-byte-sequence" title="deflate a DOMString into a byte sequence">deflating</a>
                    664:    <var>method</var>.</li> <!-- This sounds lame, but it works. -->
1.91      avankest  665: 
                    666:    <li>
1.258     avankest  667:     <p>If <var>method</var> is a case-insensitive match for
1.343     avankest  668:     <code>CONNECT</code>, <code>DELETE</code>, <code>GET</code>,
                    669:     <code>HEAD</code>, <code>OPTIONS</code>, <code>POST</code>,
                    670:     <code>PUT</code>, <code>TRACE</code>, or <code>TRACK</code>
                    671:     subtract 0x20 from each byte in the range 0x61 (ASCII a) to
                    672:     0x7A (ASCII z).</p>
1.205     avankest  673: 
1.343     avankest  674:     <p class="note">If it does not match any of the above, it is passed
                    675:     through <em>literally</em>, including in the final request.</p>
1.205     avankest  676:    </li>
                    677:    <!-- WebKit (and supposedly Gecko) also uppercase: COPY, INDEX, LOCK,
                    678:    M-POST, MKCOL, MOVE, PROPFIND, PROPPATCH, and UNLOCK. -->
1.89      avankest  679: 
1.205     avankest  680:    <li>
1.258     avankest  681:     <p>If <var>method</var> is a case-sensitive match for
1.343     avankest  682:     <code>CONNECT</code>, <code>TRACE</code>, or <code>TRACK</code>  raise a
                    683:     <code class="external" title="dom-DOMException-SECURITY_ERR"><a href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#dom-domexception-security_err">SECURITY_ERR</a></code> exception and terminate these steps.</p>
1.164     avankest  684: 
1.343     avankest  685:     <p class="note">Allowing these methods poses a security risk.
                    686:     <a href="#refsHTTPVERBSEC">[HTTPVERBSEC]</a>
                    687:    </li>
                    688: 
                    689:    <li><p>Let <var title="">url</var> be a
1.346     avankest  690:    <a class="external" href="http://www.whatwg.org/specs/web-apps/current-work/multipage/urls.html#url">URL</a> with character encoding UTF-8.
1.89      avankest  691: 
1.343     avankest  692:    <li><p><span title="Resolve a URL">Resolve</span> <var title="">url</var>
                    693:    relative to the <a href="#xmlhttprequest-base-url"><code>XMLHttpRequest</code> base URL</a>.
                    694:    If the algorithm returns an error raise a <code class="external" title="dom-DOMException-SYNTAX_ERR"><a href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#dom-domexception-syntax_err">SYNTAX_ERR</a></code>
                    695:    exception and terminate these steps.</li>
1.89      avankest  696: 
1.205     avankest  697:    <!-- Presto and Gecko override the encoding. WebKit does not. Trident
                    698:    does not support non-ASCII URLs. This matters for the <query> component,
1.330     avankest  699:    see HTML. -->
1.129     avankest  700: 
1.343     avankest  701:    <li><p>Drop
1.346     avankest  702:    <code class="external" title="url-fragment"><a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/urls.html#url-fragment">&lt;fragment&gt;</a></code> from
1.343     avankest  703:    <var title="">url</var>.</li>
                    704: 
                    705:    <li><p>If the <code>"user:password"</code> format in the
                    706:    <code class="external"><a href="http://tools.ietf.org/html/rfc2616/#section-3.2.1">userinfo</a></code> production is not supported
                    707:    for the relevant
1.346     avankest  708:    <code class="external" title="url-scheme"><a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/urls.html#url-scheme">&lt;scheme&gt;</a></code> and
1.343     avankest  709:    <var title="">url</var> contains this format raise a
                    710:    <code class="external" title="dom-DOMException-SYNTAX_ERR"><a href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#dom-domexception-syntax_err">SYNTAX_ERR</a></code>
                    711:    and terminate these steps.</li>
1.89      avankest  712: 
1.314     avankest  713:    <!-- XXX need to throw here for "user:password" or just "user" for
                    714:             cross-origin unless we solve this in another way -->
1.2       avankest  715: 
1.343     avankest  716:    <li><p>If <var title="">url</var> contains the <code>"user:password"</code>
                    717:    format let <var>temp user</var> be the user part and
                    718:    <var>temp password</var> be the password part.</li>
1.2       avankest  719: 
1.343     avankest  720:    <li><p>If <var title="">url</var> just contains the <code>"user"</code>
                    721:    format let <var>temp user</var> be the user part.</li>
1.2       avankest  722: 
1.343     avankest  723:    <li><p>Let <var>async</var> be the value of the <var>async</var> argument
                    724:    or true if it was omitted.</li>
1.2       avankest  725: 
1.205     avankest  726:    <li>
1.343     avankest  727:     <p>If the <var title="">user</var> argument was not omitted follow these
                    728:     sub steps:</p>
1.2       avankest  729: 
1.60      avankest  730:     <ol>
1.343     avankest  731:      <li><p>If <var title="">user</var> is not null and the
1.346     avankest  732:      <a class="external" href="http://www.whatwg.org/specs/web-apps/current-work/multipage/origin-0.html#origin">origin</a> of <var title="">url</var> is not
                    733:      <a class="external" href="http://www.whatwg.org/specs/web-apps/current-work/multipage/origin-0.html#same-origin">same origin</a> with the
1.343     avankest  734:      <a href="#xmlhttprequest-origin"><code>XMLHttpRequest</code> origin</a> raise an
                    735:      <code class="external" title="dom-DOMException-INVALID_ACCESS_ERR"><a href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#dom-domexception-invalid_access_err">INVALID_ACCESS_ERR</a></code> exception and terminate the overall set
                    736:      of steps.</li>
1.2       avankest  737: 
1.343     avankest  738:      <li><p>Let <var>temp user</var> be <var>user</var>.</li>
1.205     avankest  739:     </ol>
1.184     avankest  740: 
1.343     avankest  741:     <p class="note">These steps override anything that may have been set by
                    742:     the <var title="">url</var> argument.</p>
                    743:    </li>
1.157     avankest  744: 
1.205     avankest  745:    <li>
1.343     avankest  746:     <p>If the <var title="">password</var> argument was not omitted follow
                    747:     these sub steps:</p>
1.2       avankest  748: 
1.205     avankest  749:     <ol>
1.343     avankest  750:      <li><p>If <var title="">password</var> is not null and the
1.346     avankest  751:      <a class="external" href="http://www.whatwg.org/specs/web-apps/current-work/multipage/origin-0.html#origin">origin</a> of <var title="">url</var> is not
                    752:      <a class="external" href="http://www.whatwg.org/specs/web-apps/current-work/multipage/origin-0.html#same-origin">same origin</a> with the
1.343     avankest  753:      <a href="#xmlhttprequest-origin"><code>XMLHttpRequest</code> origin</a> raise an
                    754:      <code class="external" title="dom-DOMException-INVALID_ACCESS_ERR"><a href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#dom-domexception-invalid_access_err">INVALID_ACCESS_ERR</a></code> exception and terminate the overall set
                    755:      of steps.</li>
1.2       avankest  756: 
1.343     avankest  757:      <li><p>Let <var>temp password</var> be <var>password</var>.</li>
1.205     avankest  758:     </ol>
1.102     avankest  759: 
1.343     avankest  760:     <p class="note">These steps override anything that may have been set by
                    761:     the <var title="">url</var> argument.</p>
                    762:    </li>
1.2       avankest  763: 
1.343     avankest  764:    <li><p><a href="#terminate-abort" title="terminate abort()">Terminate the <code>abort()</code> algorithm</a>.</li>
1.319     avankest  765: 
1.343     avankest  766:    <li><p><a href="#terminate-send" title="terminate send()">Terminate the <code>send()</code> algorithm</a>.</li>
1.2       avankest  767: 
1.343     avankest  768:    <li><p>The user agent should cancel any network
                    769:    activity for which the object is responsible.</li>
1.205     avankest  770:    <!-- we can hardly require it... -->
1.24      avankest  771: 
1.343     avankest  772:    <li><p>If there are any
1.346     avankest  773:    <a class="external" href="http://www.whatwg.org/specs/web-apps/current-work/multipage/webappapis.html#concept-task" title="concept-task">tasks</a> from the
1.343     avankest  774:    object's <a href="#xmlhttprequest-task-source"><code>XMLHttpRequest</code> task source</a> in one of
1.346     avankest  775:    the <a class="external" href="http://www.whatwg.org/specs/web-apps/current-work/multipage/webappapis.html#task-queue" title="task queue">task queues</a>,
1.343     avankest  776:    then remove them.
1.254     avankest  777: 
                    778:    <li>
1.205     avankest  779:     <p>Set variables associated with the object as follows:</p>
1.70      avankest  780: 
1.205     avankest  781:     <ul>
1.17      avankest  782: 
1.343     avankest  783:      <li><p>Set the <a href="#request-method">request method</a> to <var>method</var>.</li>
                    784: 
                    785:      <li><p>Set the <a href="#request-url">request URL</a> to <var title="">url</var>.</li>
                    786: 
                    787:      <li><p>Set the <a href="#asynchronous-flag">asynchronous flag</a> to the value of
                    788:      <var>async</var>.</li>
1.341     avankest  789: 
1.343     avankest  790:      <li><p>Set the <a href="#request-username">request username</a> to <var>temp user</var>.</li>
1.341     avankest  791: 
1.343     avankest  792:      <li><p>Set the <a href="#request-password">request password</a> to <var>temp password</var>.</li>
1.17      avankest  793: 
1.343     avankest  794:      <li><p>Empty the list of <a href="#author-request-headers">author request headers</a>.</p>
1.308     avankest  795: 
1.343     avankest  796:      
1.17      avankest  797: 
1.343     avankest  798:      <li><p>Set the <a href="#send-flag"><code>send()</code> flag</a> to false.</li>
1.17      avankest  799: 
1.343     avankest  800:      <li><p>Set <a href="#response-entity-body">response entity body</a> to null.</li>
1.205     avankest  801:     </ul>
1.343     avankest  802:    </li>
1.44      avankest  803: 
1.343     avankest  804:    <li><p>Switch the state to
                    805:    <a href="#dom-xmlhttprequest-opened" title="dom-XMLHttpRequest-OPENED">OPENED</a>.</li>
1.176     avankest  806: 
1.343     avankest  807:    <li><p><a class="external" href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-event-fire" title="concept-event-fire">Fire an event</a> named <code title="event-xhr-readystatechange">readystatechange</code>.</li>
1.205     avankest  808:   </ol>
1.22      avankest  809: 
1.275     avankest  810: 
1.343     avankest  811: 
                    812:   <h4 id="the-setrequestheader-method"><span class="secno">4.6.2 </span>The <code title="">setRequestHeader()</code> method</h4>
                    813: 
                    814:   <dl class="domintro">
                    815:    <dt><var title="">client</var> . <code title="dom-XMLHttpRequest-setRequestHeader"><a href="#dom-xmlhttprequest-setrequestheader">setRequestHeader(<var title="">header</var>, <var title="">value</var>)</a></code></dt>
1.275     avankest  816: 
                    817:    <dd>
1.343     avankest  818:     <p>Appends an header to the list of
                    819:     <a href="#author-request-headers">author request headers</a>, or if <var>header</var> is already
                    820:     in the list of <a href="#author-request-headers">author request headers</a>, combines its value
                    821:     with <var>value</var>.</p>
                    822: 
                    823:     <p>Throws an <code class="external" title="dom-DOMException-INVALID_STATE_ERR"><a href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#dom-domexception-invalid_state_err">INVALID_STATE_ERR</a></code> exception if the state is
                    824:     not <a href="#dom-xmlhttprequest-opened" title="dom-XMLHttpRequest-OPENED">OPENED</a> or if the
                    825:     <a href="#send-flag"><code>send()</code> flag</a> is true.</p>
                    826: 
                    827:     <p>Throws a <code class="external" title="dom-DOMException-SYNTAX_ERR"><a href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#dom-domexception-syntax_err">SYNTAX_ERR</a></code> exception if
                    828:     <var title="">header</var> is not a valid HTTP header field name or if
                    829:     <var title="">value</var> is not a valid HTTP header field value.</p>
                    830:    </dd>
1.275     avankest  831:   </dl>
1.205     avankest  832: 
1.343     avankest  833:   <p class="note">As indicated in the algorithm below certain headers cannot
                    834:   be set and are left up to the user agent. In addition there are certain
                    835:   other headers the user agent will take control of if they are not set by
                    836:   the author as indicated at the end of the
                    837:   <code title="dom-XMLHttpRequest-send"><a href="#dom-xmlhttprequest-send">send()</a></code> method section.</p>
                    838: 
                    839:   
                    840: 
                    841:   <p>When the
                    842:   <dfn id="dom-xmlhttprequest-setrequestheader" title="dom-XMLHttpRequest-setRequestHeader"><code>setRequestHeader(<var title="">header</var>, <var title="">value</var>)</code></dfn>
                    843:   method is invoked, the user agent must run these
                    844:   steps:</p>
1.6       avankest  845: 
1.205     avankest  846:   <ol>
1.343     avankest  847:    <li><p>If the state is not <a href="#dom-xmlhttprequest-opened" title="dom-XMLHttpRequest-OPENED">OPENED</a> raise
                    848:    an <code class="external" title="dom-DOMException-INVALID_STATE_ERR"><a href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#dom-domexception-invalid_state_err">INVALID_STATE_ERR</a></code> exception and terminate these
                    849:    steps.</li>
                    850: 
                    851:    <li><p>If the <a href="#send-flag"><code>send()</code> flag</a> is true raise an
                    852:    <code class="external" title="dom-DOMException-INVALID_STATE_ERR"><a href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#dom-domexception-invalid_state_err">INVALID_STATE_ERR</a></code> exception and terminate these
                    853:    steps.</li>
                    854: 
                    855:    <li><p>If any code point in <var>header</var> is higher than
                    856:    U+00FF LATIN SMALL LETTER Y WITH DIAERESIS or after
                    857:    <a href="#deflate-a-domstring-into-a-byte-sequence" title="deflate a DOMString into a byte sequence">deflating</a>
                    858:    <var>header</var> it does not match the
                    859:    <a class="external" href="http://tools.ietf.org/html/rfc2616/#section-4.2">field-name</a> production raise a
                    860:    <code class="external" title="dom-DOMException-SYNTAX_ERR"><a href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#dom-domexception-syntax_err">SYNTAX_ERR</a></code>
                    861:    exception and terminate these steps. Otherwise let <var>header</var> be
                    862:    the result of
                    863:    <a href="#deflate-a-domstring-into-a-byte-sequence" title="deflate a DOMString into a byte sequence">deflating</a>
                    864:    <var>header</var>.</li> <!-- This sounds lame, but it works. -->
                    865: 
                    866:    <li>
                    867:     <p>If any code point in <var>value</var> is higher than
                    868:     U+00FF LATIN SMALL LETTER Y WITH DIAERESIS or after
                    869:     <a href="#deflate-a-domstring-into-a-byte-sequence" title="deflate a DOMString into a byte sequence">deflating</a>
                    870:     <var>value</var> it does not match the
                    871:     <a class="external" href="http://tools.ietf.org/html/rfc2616/#section-4.2">field-value</a> production raise a
                    872:     <code class="external" title="dom-DOMException-SYNTAX_ERR"><a href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#dom-domexception-syntax_err">SYNTAX_ERR</a></code>
                    873:     exception and terminate these steps. Otherwise let <var>value</var> be
                    874:     the result of
                    875:     <a href="#deflate-a-domstring-into-a-byte-sequence" title="deflate a DOMString into a byte sequence">deflating</a>
                    876:     <var>value</var>.</p> <!-- This sounds lame, but it works. -->
1.47      avankest  877: 
1.343     avankest  878:     <p class="note">The empty string is legal and represents the empty
                    879:     header value.</p>
1.258     avankest  880:    </li>
1.6       avankest  881: 
1.205     avankest  882:    <li>
1.343     avankest  883:     <p>Terminate these steps if <var>header</var> is a case-insensitive
                    884:     match for one of the following headers:</p>
1.179     avankest  885: 
1.205     avankest  886:     <ul>
1.343     avankest  887:      <li><code>Accept-Charset</code></li>
                    888:      <li><code>Accept-Encoding</code></li>
                    889:      <li><code>Connection</code></li>
                    890:      <li><code>Content-Length</code></li>
                    891:      <li><code>Cookie</code></li>
                    892:      <li><code>Cookie2</code></li>
                    893:      <li><code>Content-Transfer-Encoding</code></li>
                    894:      <li><code>Date</code></li>
                    895:      <li><code>Expect</code></li>
                    896:      <li><code>Host</code></li>
                    897:      <li><code>Keep-Alive</code></li>
                    898:      <li><code>Referer</code></li>
                    899:      <li><code>TE</code></li>
                    900:      <li><code>Trailer</code></li>
                    901:      <li><code>Transfer-Encoding</code></li>
                    902:      <li><code>Upgrade</code></li>
                    903:      <li><code>User-Agent</code></li>
                    904:      <li><code>Via</code></li>
1.205     avankest  905:     </ul>
1.69      avankest  906: 
1.258     avankest  907:     <p>&hellip; or if the start of <var>header</var> is a case-insensitive
1.343     avankest  908:     match for <code>Proxy-</code> or <code>Sec-</code> (including when
                    909:     <var>header</var> is just <code>Proxy-</code> or <code>Sec-</code>).</p>
1.342     avankest  910: 
1.343     avankest  911:     <p class="note">The above headers are controlled by the user agent to
                    912:     let it control those aspects of transport. This guarantees data
                    913:     integrity to some extent. Header names starting with <code>Sec-</code>
                    914:     are not allowed to be set to allow new headers to be minted that are
                    915:     guaranteed not to come from <code><a href="#xmlhttprequest">XMLHttpRequest</a></code>.</p>
                    916:    </li>
1.205     avankest  917: 
1.343     avankest  918:    <li><p>If <var>header</var> is not in the
                    919:    <a href="#author-request-headers">author request headers</a> list append <var>header</var> with
                    920:    its associated <var>value</var> to the list and terminate these
                    921:    steps.</li>
                    922: 
                    923:    <li><p>If <var>header</var> is in the <a href="#author-request-headers">author request headers</a>
                    924:    list either use multiple headers, combine the values or use a combination
                    925:    of those (section 4.2, RFC 2616).
                    926:    <a href="#refsHTTP">[HTTP]</a>
                    927:    <!-- XXX it seems UAs always combine the values -->
1.205     avankest  928:   </ol>
1.18      avankest  929: 
1.343     avankest  930:   <p class="note">See also the
                    931:   <code title="dom-XMLHttpRequest-send"><a href="#dom-xmlhttprequest-send">send()</a></code> method regarding user
                    932:   agent header handling for caching, authentication, proxies, and
                    933:   cookies.</p>
1.47      avankest  934: 
1.343     avankest  935:   <div class="example">
1.316     avankest  936:    <p>Some simple code demonstrating what happens when setting the same
1.343     avankest  937:    header twice:</p>
1.316     avankest  938: 
1.205     avankest  939:    <pre><code>// The following script:
1.18      avankest  940: var client = new XMLHttpRequest();
                    941: client.open('GET', 'demo.cgi');
                    942: client.setRequestHeader('X-Test', 'one');
                    943: client.setRequestHeader('X-Test', 'two');
                    944: client.send();
                    945: 
1.316     avankest  946: // &hellip;results in the following header being sent:
                    947: X-Test: one, two</code></pre>
1.205     avankest  948:   </div>
1.6       avankest  949: 
1.343     avankest  950:   
1.341     avankest  951: 
1.276     avankest  952: 
1.343     avankest  953:   <h4 id="the-send-method"><span class="secno">4.6.3 </span>The <code title="">send()</code> method</h4>
                    954: 
                    955:   <dl class="domintro">
                    956:    <dt><var title="">client</var> . <code title="dom-XMLHttpRequest-send"><a href="#dom-xmlhttprequest-send">send(<var title="">data</var>)</a></code></dt>
1.276     avankest  957:    <dd>
1.343     avankest  958:     <p>Initiates the request. The optional argument provides the
                    959:     <a href="#request-entity-body">request entity body</a>. The argument is ignored if
                    960:     <a href="#request-method">request method</a> is <code>GET</code> or
                    961:     <code>HEAD</code>.</p>
                    962: 
                    963:     <p>Throws an <code class="external" title="dom-DOMException-INVALID_STATE_ERR"><a href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#dom-domexception-invalid_state_err">INVALID_STATE_ERR</a></code> exception if the state is
                    964:     not <a href="#dom-xmlhttprequest-opened" title="dom-XMLHttpRequest-OPENED">OPENED</a> or if the
                    965:     <a href="#send-flag"><code>send()</code> flag</a> is true.</p>
                    966:    </dd>
1.276     avankest  967:   </dl>
1.205     avankest  968: 
1.343     avankest  969:   <p>When the
                    970:   <dfn id="dom-xmlhttprequest-send" title="dom-XMLHttpRequest-send"><code>send(<var>data</var>)</code></dfn>
                    971:   method is invoked, the user agent must run these steps
                    972:   (unless otherwise noted). This algorithm can be
                    973:   <dfn id="terminate-send" title="terminate send()">terminated</dfn> by invoking the
                    974:   <code title="dom-XMLHttpRequest-open"><a href="#dom-xmlhttprequest-open">open()</a></code> or
                    975:   <code title="dom-XMLHttpRequest-abort"><a href="#dom-xmlhttprequest-abort">abort()</a></code> method. When it is
                    976:   <a href="#terminate-send" title="terminate send()">terminated</a> the user agent
                    977:   must terminate the algorithm after finishing the step
                    978:   it is on.</p>
                    979: 
                    980:   <p class="note">The <code title="dom-XMLHttpRequest-send"><a href="#dom-xmlhttprequest-send">send()</a></code>
                    981:   algorithm can only be terminated when the <a href="#asynchronous-flag">asynchronous flag</a>
                    982:   is true and only after the method call has returned.</p>
1.60      avankest  983: 
1.205     avankest  984:   <ol>
1.343     avankest  985:    <li><p>If the state is not <a href="#dom-xmlhttprequest-opened" title="dom-XMLHttpRequest-OPENED">OPENED</a> raise
                    986:    an <code class="external" title="dom-DOMException-INVALID_STATE_ERR"><a href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#dom-domexception-invalid_state_err">INVALID_STATE_ERR</a></code> exception and terminate these
                    987:    steps.</li>
                    988: 
                    989:    <li><p>If the <a href="#send-flag"><code>send()</code> flag</a> is true raise an
                    990:    <code class="external" title="dom-DOMException-INVALID_STATE_ERR"><a href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#dom-domexception-invalid_state_err">INVALID_STATE_ERR</a></code> exception and terminate these
                    991:    steps.</li>
                    992: 
                    993:    <li>
                    994:     <p>If the <a href="#request-method">request method</a> is a case-sensitive match for
                    995:     <code>GET</code> or <code>HEAD</code> act as if <var title="">data</var>
                    996:     is null.</p>
                    997: 
                    998:     <p>If the <var>data</var> argument has been omitted or is
                    999:     null, do not include a <a href="#request-entity-body">request entity body</a>
                   1000:     and go to the next step.</p>
1.342     avankest 1001: 
1.343     avankest 1002:     <p>Otherwise, let <var>encoding</var> be null, <var>mime type</var> be
                   1003:     null, and then follow these rules:</p>
1.342     avankest 1004: 
1.343     avankest 1005:     <dl class="switch">
                   1006:      
1.60      avankest 1007: 
1.343     avankest 1008:      <dt>If <var>data</var> is a <code class="external"><a href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#document">Document</a></code>
1.205     avankest 1009: 
                   1010:      <dd>
1.343     avankest 1011:       <p>Let <var>encoding</var> be the
                   1012:       <a class="external" href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#preferred-mime-name">preferred MIME name</a> of the
                   1013:       <a class="external" href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-document-character-encoding" title="concept-document-character-encoding">character encoding</a>
                   1014:       of <var>data</var>. If <var>encoding</var> is UTF-16 change it to
                   1015:       UTF-8.</p>
1.234     avankest 1016: 
1.307     avankest 1017:       <p>Let <var>mime type</var> be "<code>application/xml</code>" or
1.343     avankest 1018:       "<code>text/html</code>" if
1.349   ! avankest 1019:       <code class="external"><a href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#document">Document</a></code> is an
1.343     avankest 1020:       <a class="external" href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#html-document">HTML document</a>, followed by
                   1021:       "<code>;charset=</code>", followed by <var>encoding</var>.</p>
                   1022: 
                   1023:       <p>Let the <a href="#request-entity-body">request entity body</a> be the result of getting
1.346     avankest 1024:       the <code class="external" title="dom-innerHTML"><a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/content-models.html#dom-innerhtml">innerHTML</a></code>
1.343     avankest 1025:       attribute on <var>data</var>
                   1026:       <a class="external" href="http://dev.w3.org/2006/webapi/WebIDL/#dfn-obtain-unicode" title="convert a DOMString to a sequence of Unicode characters">converted to Unicode</a>
                   1027:       and encoded as <var>encoding</var>. Re-raise any exception this
                   1028:       raises.</p>
                   1029: 
                   1030:       <p class="note">In particular, if the document cannot be serialized an
                   1031:       <code class="external" title="dom-DOMException-INVALID_STATE_ERR"><a href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#dom-domexception-invalid_state_err">INVALID_STATE_ERR</a></code>
                   1032:       exception is raised.</p>
                   1033: 
                   1034:       <p class="note">Subsequent changes to the
                   1035:       <code class="external"><a href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#document">Document</a></code> have no effect on what
                   1036:       is transferred.</p>
                   1037:      </dd>
1.239     avankest 1038: 
1.343     avankest 1039:      <dt>If <var>data</var> is a <code>DOMString</code></dt>
1.239     avankest 1040: 
                   1041:      <dd>
1.250     avankest 1042:       <p>Let <var>encoding</var> be UTF-8.</p>
                   1043: 
                   1044:       <p>Let <var>mime type</var> be "<code>text/plain;charset=UTF-8</code>".</p>
                   1045: 
1.343     avankest 1046:       <p>Let the <a href="#request-entity-body">request entity body</a> be <var>data</var>
                   1047:       <a class="external" href="http://dev.w3.org/2006/webapi/WebIDL/#dfn-obtain-unicode" title="convert a DOMString to a sequence of Unicode characters">converted to Unicode</a>
                   1048:       and encoded as UTF-8.</p>
                   1049:      </dd>
                   1050: 
                   1051:      
1.205     avankest 1052:     </dl>
1.103     avankest 1053: 
1.343     avankest 1054:     <p>If a <code>Content-Type</code> header is set using
                   1055:     <code title="dom-XMLHttpRequest-setRequestHeader"><a href="#dom-xmlhttprequest-setrequestheader">setRequestHeader()</a></code>
1.346     avankest 1056:     whose value is a <a class="external" href="http://www.whatwg.org/specs/web-apps/current-work/multipage/infrastructure.html#valid-mime-type">valid MIME type</a> and
1.343     avankest 1057:     has a <code>charset</code> parameter whose value is not a case-insensitive
                   1058:     match for <var title="">encoding</var>, and <var title="">encoding</var>
                   1059:     is not null, set all the <code>charset</code> parameters of the
                   1060:     <code>Content-Type</code> header to <var title="">encoding</var>.</p>
                   1061: 
                   1062:     <p>If no <code>Content-Type</code> header has been set using
                   1063:     <code title="dom-XMLHttpRequest-setRequestHeader"><a href="#dom-xmlhttprequest-setrequestheader">setRequestHeader()</a></code>
                   1064:     and <var title="">mime type</var> is not null set a
                   1065:     <code>Content-Type</code> request header with as value
                   1066:     <var title="">mime type</var>.</p>
                   1067: 
1.238     avankest 1068:     <!-- reminder: if we ever change this to always include charset it has
                   1069:     to be included as the first parameter for compatibility reasons -->
1.343     avankest 1070:    </li>
                   1071: 
                   1072:    <li><p>If the <a href="#asynchronous-flag">asynchronous flag</a> is false release the
1.346     avankest 1073:    <a class="external" href="http://www.whatwg.org/specs/web-apps/current-work/multipage/webappapis.html#storage-mutex">storage mutex</a>.</li>
1.343     avankest 1074: 
                   1075:    
1.341     avankest 1076: 
1.343     avankest 1077:    <li><p>Set the <a href="#error-flag">error flag</a> to false.</li>
1.341     avankest 1078: 
1.343     avankest 1079:    
1.164     avankest 1080: 
1.205     avankest 1081:    <li>
1.343     avankest 1082:     <p>If the <a href="#asynchronous-flag">asynchronous flag</a> is true run these substeps:</p>
1.213     avankest 1083: 
                   1084:     <ol>
1.343     avankest 1085:      <li><p>Set the <a href="#send-flag"><code>send()</code> flag</a> to true.</li>
                   1086: 
1.342     avankest 1087:      <li>
1.343     avankest 1088:       <p><a class="external" href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-event-fire" title="concept-event-fire">Fire an event</a> named <code title="event-xhr-readystatechange">readystatechange</code>.
1.341     avankest 1089: 
1.343     avankest 1090:       <p class="note">The state does not change. The event is dispatched for
                   1091:       historical reasons.</p>
                   1092:      </li>
1.219     avankest 1093: 
1.343     avankest 1094:      
1.213     avankest 1095: 
1.343     avankest 1096:      <li><p>Return the <code title="dom-XMLHttpRequest-send"><a href="#dom-xmlhttprequest-send">send()</a></code>
                   1097:      method call, but continue running the steps in this algorithm.</li>
1.213     avankest 1098:     </ol>
1.343     avankest 1099:    </li>
1.213     avankest 1100: 
                   1101:    <li>
1.343     avankest 1102:     <dl class="switch">
                   1103:      <dt>If the <a href="#xmlhttprequest-origin"><code>XMLHttpRequest</code> origin</a> and the
1.346     avankest 1104:      <a href="#request-url">request URL</a> are <a class="external" href="http://www.whatwg.org/specs/web-apps/current-work/multipage/origin-0.html#same-origin">same origin</a></dt>
1.195     avankest 1105: 
1.205     avankest 1106:      <dd>
1.343     avankest 1107:       <p>These are the <dfn id="same-origin-request-steps">same-origin request steps</dfn>.</p>
1.342     avankest 1108: 
1.346     avankest 1109:       <p><a class="external" href="http://www.whatwg.org/specs/web-apps/current-work/multipage/urls.html#fetch">Fetch</a> the
1.343     avankest 1110:       <a href="#request-url">request URL</a> from <i title="">origin</i>
                   1111:       <a href="#xmlhttprequest-origin"><code>XMLHttpRequest</code> origin</a>, with the
                   1112:       <i title="">synchronous flag</i> set if the
                   1113:       <a href="#asynchronous-flag">asynchronous flag</a> is false, using HTTP method
                   1114:       <a href="#request-method">request method</a>, user <a href="#request-username">request username</a> (if
                   1115:       non-null) and password <a href="#request-password">request password</a> (if non-null),
                   1116:       taking into account the <a href="#request-entity-body">request entity body</a>, list of
                   1117:       <a href="#author-request-headers">author request headers</a> and the rules listed at the end of
                   1118:       this section.</p>
1.305     avankest 1119: 
1.343     avankest 1120:       <dl class="switch">
                   1121:        <dt>If the <a href="#asynchronous-flag">asynchronous flag</a> is false</dt>
                   1122:        <dd>
                   1123:         <p>While making the request also follow the
                   1124:         <a href="#same-origin-request-event-rules">same-origin request event rules</a>.</p>
1.305     avankest 1125: 
                   1126:         <!--
1.250     avankest 1127:          This cannot involve any task queue whatsoever because that would
                   1128:          mean other tasks on the task queue might get processed as well
                   1129:          which is counter to the whole idea of doing things synchronous.
                   1130:         -->
1.305     avankest 1131: 
1.343     avankest 1132:         <p class="note">The
                   1133:         <code title="dom-XMLHttpRequest-send"><a href="#dom-xmlhttprequest-send">send()</a></code> method call will
                   1134:         now be returned by virtue of this algorithm ending.</p>
                   1135:        </dd>
1.305     avankest 1136: 
1.343     avankest 1137:        <dt>If the <a href="#asynchronous-flag">asynchronous flag</a> is true</dt>
1.305     avankest 1138:        <dd>
1.343     avankest 1139:         
                   1140: 
1.305     avankest 1141:         <p>While processing the request, as data becomes available and when
1.343     avankest 1142:         the user interferes with the request,
1.346     avankest 1143:         <a class="external" href="http://www.whatwg.org/specs/web-apps/current-work/multipage/webappapis.html#queue-a-task" title="queue a task">queue tasks</a>
1.343     avankest 1144:         to update the <a href="#response-entity-body">response entity body</a> and follow the
                   1145:         <a href="#same-origin-request-event-rules">same-origin request event rules</a>.</p>
                   1146:        </dd>
1.305     avankest 1147:       </dl>
1.343     avankest 1148:      </dd>
1.205     avankest 1149: 
1.343     avankest 1150:      <dt>Otherwise</dt>
1.205     avankest 1151:      <dd>
1.343     avankest 1152:       <p>These are the <dfn id="cross-origin-request-steps">cross-origin request steps</dfn>.</p>
1.250     avankest 1153: 
1.343     avankest 1154:       
1.305     avankest 1155:       <p>This is a <a href="#network-error">network error</a>.</p>
1.343     avankest 1156:       
                   1157: 
                   1158:       
                   1159:      </dd>
1.205     avankest 1160:     </dl>
1.343     avankest 1161:    </li>
1.205     avankest 1162:   </ol>
1.124     avankest 1163: 
1.205     avankest 1164:   <hr>
                   1165: 
1.343     avankest 1166:   <p>If the user agent allows the end user to configure a proxy it
                   1167:   should modify the request appropriately; i.e., connect
                   1168:   to the proxy host instead of the origin server, modify the
                   1169:   <code>Request-Line</code> and send <code>Proxy-Authorization</code>
                   1170:   headers as specified.</p>
1.214     avankest 1171: 
1.264     avankest 1172:   <hr>
                   1173: 
1.343     avankest 1174:   <p>If the user agent supports HTTP Authentication and
                   1175:   <code title="http-authorization">Authorization</code> is not in the list
                   1176:   of <a href="#author-request-headers">author request headers</a>, it should
                   1177:   consider requests originating from the <code><a href="#xmlhttprequest">XMLHttpRequest</a></code> object
                   1178:   to be part of the protection space that includes the accessed URIs and
                   1179:   send <code title="http-authorization">Authorization</code> headers and
                   1180:   handle <code>401 Unauthorized</code> requests appropriately.</p>
                   1181: 
                   1182:   <p>If authentication fails,
                   1183:   <a href="#xmlhttprequest-origin"><code>XMLHttpRequest</code> origin</a> and the
1.346     avankest 1184:   <a href="#request-url">request URL</a> are <a class="external" href="http://www.whatwg.org/specs/web-apps/current-work/multipage/origin-0.html#same-origin">same origin</a>,
1.343     avankest 1185:   <code title="http-authorization">Authorization</code> is not in the list
                   1186:   of <a href="#author-request-headers">author request headers</a>, <a href="#request-username">request username</a> is
                   1187:   null, and <a href="#request-password">request password</a> is null, user agents
                   1188:   should prompt the end user for their username and
                   1189:   password.</p>
                   1190: 
                   1191:   <p>Otherwise, if authentication fails, user agents
                   1192:   must not prompt the end user for their username and
                   1193:   password. <a href="#refsHTTPAUTH">[HTTPAUTH]</a>
1.315     avankest 1194: 
1.343     avankest 1195:   <p class="note">End users are not prompted for various cases so that
                   1196:   authors can implement their own user interface.</p>
1.214     avankest 1197: 
1.264     avankest 1198:   <hr>
                   1199: 
1.343     avankest 1200:   <p>If the user agent supports HTTP State Management it
                   1201:   should persist, discard and send cookies (as received
                   1202:   in the <code>Set-Cookie</code> response header, and sent in the
                   1203:   <code>Cookie</code> header) as applicable.
                   1204:   <a href="#refsCOOKIES">[COOKIES]</a>
1.214     avankest 1205: 
1.264     avankest 1206:   <hr>
                   1207: 
1.343     avankest 1208:   <p>If the user agent implements a HTTP cache it should
                   1209:   respect <code>Cache-Control</code> request headers set by the
                   1210:   <code title="dom-XMLHttpRequest-setRequestHeader"><a href="#dom-xmlhttprequest-setrequestheader">setRequestHeader()</a></code>
                   1211:   (e.g., <code>Cache-Control: no-cache</code> bypasses the cache). It
                   1212:   must not send <code>Cache-Control</code> or
                   1213:   <code>Pragma</code> request headers automatically unless the end user
                   1214:   explicitly requests such behavior (e.g. by reloading the page).</p>
                   1215: 
                   1216:   <p>For <code>304 Not Modified</code> responses that are a result of a
                   1217:   user agent generated conditional request the user agent
                   1218:   must act as if the server gave a <code>200 OK</code>
                   1219:   response with the appropriate content. The user agent
                   1220:   must allow
                   1221:   <code title="dom-XMLHttpRequest-setRequestHeader"><a href="#dom-xmlhttprequest-setrequestheader">setRequestHeader()</a></code>
                   1222:   to override automatic cache validation by setting request headers (e.g.
                   1223:   <code>If-None-Match</code> or <code>If-Modified-Since</code>), in which
                   1224:   case <code>304 Not Modified</code> responses must be
                   1225:   passed through. <a href="#refsHTTP">[HTTP]</a>
1.214     avankest 1226: 
1.264     avankest 1227:   <hr>
                   1228: 
1.343     avankest 1229:   <p>If the user agent implements server-driven content-negotiation
                   1230:   it must follow these constraints for the
                   1231:   <code>Accept</code> and <code>Accept-Language</code> request headers:</p>
1.233     avankest 1232: 
                   1233:   <ul>
1.343     avankest 1234:    <li><p>Both headers must not be modified if they are
                   1235:    already set through
                   1236:    <code title="dom-XMLHttpRequest-setRequestHeader"><a href="#dom-xmlhttprequest-setrequestheader">setRequestHeader()</a></code>.</li>
                   1237: 
                   1238:    <li><p>If not set through
                   1239:    <code title="dom-XMLHttpRequest-setRequestHeader"><a href="#dom-xmlhttprequest-setrequestheader">setRequestHeader()</a></code>
                   1240:    <code>Accept-Language</code> should be set as
                   1241:    appropriate.</li>
                   1242: 
                   1243:    <li><p>If not set through
                   1244:    <code title="dom-XMLHttpRequest-setRequestHeader"><a href="#dom-xmlhttprequest-setrequestheader">setRequestHeader()</a></code>
                   1245:    <code>Accept</code> must be set with as value
                   1246:    <code>*/*</code>.</li>
1.233     avankest 1247:   </ul>
                   1248: 
1.343     avankest 1249:   <p>Responses must have the content-encodings
                   1250:   automatically decoded. <a href="#refsHTTP">[HTTP]</a>
1.214     avankest 1251: 
1.264     avankest 1252:   <hr>
                   1253: 
1.343     avankest 1254:   <p>Besides the <a href="#author-request-headers">author request headers</a> user agents
                   1255:   should not include additional request headers other than those mentioned
                   1256:   above or other than those authors are not allowed to set using
                   1257:   <code title="dom-XMLHttpRequest-setRequestHeader"><a href="#dom-xmlhttprequest-setrequestheader">setRequestHeader()</a></code>.
                   1258:   This ensures that authors have a reasonably predictable API.</p>
1.214     avankest 1259: 
                   1260: 
1.343     avankest 1261:   <h4 id="infrastructure-for-the-send-method"><span class="secno">4.6.4 </span>Infrastructure for the <code title="">send()</code> method</h4>
1.205     avankest 1262: 
1.343     avankest 1263:   <p>The <dfn id="same-origin-request-event-rules">same-origin request event rules</dfn> are as follows:</p>
1.205     avankest 1264: 
1.343     avankest 1265:   <dl class="switch">
                   1266:    <dt>If the response has an HTTP status code of 301, 302, 303, or 307</dt>
1.205     avankest 1267:    <dd>
1.343     avankest 1268:     <p>If the redirect violates infinite loop precautions this is a
                   1269:     <a href="#network-error">network error</a>.</p>
1.205     avankest 1270: 
1.305     avankest 1271:     <p>Otherwise, run these steps:</p>
                   1272: 
                   1273:     <ol>
1.343     avankest 1274:      <li><p>Set the <a href="#request-url">request URL</a> to the
1.346     avankest 1275:      <a class="external" href="http://www.whatwg.org/specs/web-apps/current-work/multipage/urls.html#url">URL</a> conveyed by the
1.343     avankest 1276:      <code>Location</code> header.</li>
                   1277: 
                   1278:      <li><p>If the <a href="#xmlhttprequest-origin"><code>XMLHttpRequest</code> origin</a> and the
1.346     avankest 1279:      <a class="external" href="http://www.whatwg.org/specs/web-apps/current-work/multipage/origin-0.html#origin">origin</a> of <a href="#request-url">request URL</a>
                   1280:      are <a class="external" href="http://www.whatwg.org/specs/web-apps/current-work/multipage/origin-0.html#same-origin">same origin</a> transparently follow
1.343     avankest 1281:      the redirect while observing the
                   1282:      <a href="#same-origin-request-event-rules">same-origin request event rules</a>.
1.305     avankest 1283: 
1.343     avankest 1284:      <li><p>Otherwise, follow the <a href="#cross-origin-request-steps">cross-origin request steps</a>
                   1285:      and terminate the steps for this algorithm.</li>
1.305     avankest 1286:     </ol>
1.250     avankest 1287: 
1.343     avankest 1288:     <p class="note">HTTP places requirements on the user agent regarding the
                   1289:     preservation of the <a href="#request-method">request method</a> and
                   1290:     <a href="#request-entity-body">request entity body</a> during redirects, and also requires end
                   1291:     users to be notified of certain kinds of automatic redirections.</p>
1.205     avankest 1292:     <!-- XXX HTTP needs fixing here -->
1.343     avankest 1293:    </dd>
1.205     avankest 1294: 
1.343     avankest 1295:    <dt>If the end user cancels the request</dt>
                   1296:    <dd><p>This is an <a href="#abort-error">abort error</a>.</dd>
1.216     avankest 1297: 
1.343     avankest 1298:    <dt>If there is a network error</dt>
1.215     avankest 1299:    <dd>
                   1300:     <p>In case of DNS errors, TLS negotiation failure, or other type of
1.343     avankest 1301:     network errors, this is a <a href="#network-error">network error</a>. Do not request any
                   1302:     kind of end user interaction.</p>
1.342     avankest 1303: 
1.343     avankest 1304:     <p class="note">This does not include HTTP responses that indicate
                   1305:     some type of error, such as HTTP status code 410.</p>
                   1306:    </dd>
                   1307: 
                   1308:    
                   1309: 
                   1310:    <dt>Once all HTTP headers have been received, the
                   1311:    <a href="#asynchronous-flag">asynchronous flag</a> is true, and the HTTP status code of the
                   1312:    response is not 301, 302, 303, or 307</dt>
                   1313:    <dd><p><a href="#switch-headers-received">Switch to the HEADERS_RECEIVED state</a>.</dd>
                   1314: 
                   1315:    <dt>Once the first byte (or more) of the
                   1316:    <a href="#response-entity-body">response entity body</a> has been received and the
                   1317:    <a href="#asynchronous-flag">asynchronous flag</a> is true</dt>
                   1318:    <dt>If there is no <a href="#response-entity-body">response entity body</a> and the
                   1319:    <a href="#asynchronous-flag">asynchronous flag</a> is true</dt>
                   1320:    <dd><p><a href="#switch-loading">Switch to the LOADING state</a>.</dd>
                   1321: 
                   1322:    <dt>Once the whole <a href="#response-entity-body">response entity body</a> has been
                   1323:    received</dt>
                   1324:    <dt>If there is no <a href="#response-entity-body">response entity body</a> and the state is
                   1325:    <a href="#dom-xmlhttprequest-loading" title="dom-XMLHttpRequest-LOADING">LOADING</a></dt>
                   1326:    <dt>If there is no <a href="#response-entity-body">response entity body</a> and the
                   1327:    <a href="#asynchronous-flag">asynchronous flag</a> is false</dt>
                   1328:    <dd><p><a href="#switch-done">Switch to the DONE state</a>.</dd>
                   1329:   </dl>
1.342     avankest 1330: 
1.343     avankest 1331:   
1.60      avankest 1332: 
1.342     avankest 1333:   <hr>
1.6       avankest 1334: 
1.343     avankest 1335:   <p>When something is said to be a <dfn id="network-error">network error</dfn> run the
                   1336:   <a href="#request-error">request error</a> steps for exception
                   1337:   <code class="external" title="dom-DOMException-NETWORK_ERR"><a href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#dom-domexception-network_err">NETWORK_ERR</a></code>.</p>
                   1338: 
                   1339:   <p>When something is said to be an <dfn id="abort-error">abort error</dfn> run the
                   1340:   <a href="#request-error">request error</a> steps for exception
                   1341:   <code class="external" title="dom-DOMException-ABORT_ERR"><a href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#dom-domexception-abort_err">ABORT_ERR</a></code>.</p>
                   1342: 
                   1343:   
                   1344: 
                   1345:   <p>When something is said to be a <dfn id="request-error">request error</dfn> for
                   1346:   exception <var>exception</var> run these
                   1347:   steps:</p>
1.6       avankest 1348: 
1.343     avankest 1349:   <ol>
                   1350:    <li><p>The user agent should cancel any network
                   1351:    activity for which the object is responsible.</li>
1.84      avankest 1352: 
1.343     avankest 1353:    <li><p>If there are any
1.346     avankest 1354:    <a class="external" href="http://www.whatwg.org/specs/web-apps/current-work/multipage/webappapis.html#concept-task" title="concept-task">tasks</a> from the
1.343     avankest 1355:    object's <a href="#xmlhttprequest-task-source"><code>XMLHttpRequest</code> task source</a> in one of
1.346     avankest 1356:    the <a class="external" href="http://www.whatwg.org/specs/web-apps/current-work/multipage/webappapis.html#task-queue" title="task queue">task queues</a>,
1.343     avankest 1357:    then remove them.
1.60      avankest 1358: 
1.343     avankest 1359:    <li><p>Set the the <a href="#error-flag">error flag</a> to true.</li>
1.256     avankest 1360: 
1.343     avankest 1361:    <li><p>Switch the state to <a href="#dom-xmlhttprequest-done" title="dom-XMLHttpRequest-DONE">DONE</a>.</li>
1.252     avankest 1362: 
1.343     avankest 1363:    <li><p>If the <a href="#asynchronous-flag">asynchronous flag</a> is false raise an
                   1364:    <var>exception</var> exception and terminate the overall set of
                   1365:    steps.</li>
1.205     avankest 1366: 
1.342     avankest 1367:    <li>
1.343     avankest 1368:     <p><a class="external" href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-event-fire" title="concept-event-fire">Fire an event</a> named <code title="event-xhr-readystatechange">readystatechange</code>.</p>
1.205     avankest 1369: 
1.343     avankest 1370:     <p class="note">At this point it is clear that the
                   1371:     <a href="#asynchronous-flag">asynchronous flag</a> is true.</p>
                   1372:    </li>
1.250     avankest 1373: 
1.343     avankest 1374:    
1.215     avankest 1375:   </ol>
1.6       avankest 1376: 
1.343     avankest 1377:   
                   1378:   <p class="note">A future version of this specification will dispatch an
                   1379:   <code title="event-xhr-error">error</code>/<code title="event-xhr-abort">abort</code>
                   1380:   event here as well. (Depending on the type of error.)
                   1381:   
1.6       avankest 1382: 
1.215     avankest 1383:   <hr>
1.2       avankest 1384: 
1.343     avankest 1385:   <p>When it is said to
                   1386:   <dfn id="switch-headers-received">switch to the HEADERS_RECEIVED state</dfn>
                   1387:   run these steps:</p>
1.60      avankest 1388: 
1.215     avankest 1389:   <ol>
1.343     avankest 1390:    <li><p>Switch the state to <a href="#dom-xmlhttprequest-headers_received" title="dom-XMLHttpRequest-HEADERS_RECEIVED">HEADERS_RECEIVED</a>.</li>
1.125     avankest 1391: 
1.343     avankest 1392:    <li><p><a class="external" href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-event-fire" title="concept-event-fire">Fire an event</a> named <code title="event-xhr-readystatechange">readystatechange</code>.</li>
1.215     avankest 1393:   </ol>
1.205     avankest 1394: 
1.343     avankest 1395:   <p>When it is said to
                   1396:   <dfn id="switch-loading">switch to the LOADING state</dfn> run these
                   1397:   steps:</p>
1.205     avankest 1398: 
1.215     avankest 1399:   <ol>
1.343     avankest 1400:    <li><p>Switch the state to <a href="#dom-xmlhttprequest-loading" title="dom-XMLHttpRequest-LOADING">LOADING</a>.</li>
1.17      avankest 1401: 
1.343     avankest 1402:    <li><p><a class="external" href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-event-fire" title="concept-event-fire">Fire an event</a> named <code title="event-xhr-readystatechange">readystatechange</code>.</li>
1.215     avankest 1403:   </ol>
1.205     avankest 1404: 
1.343     avankest 1405:   <p>When it is said to
                   1406:   <dfn id="switch-done">switch to the DONE state</dfn> run these steps:</p>
1.218     avankest 1407: 
                   1408:   <ol>
1.343     avankest 1409:    <li><p>If the <a href="#asynchronous-flag">asynchronous flag</a> is false update the
                   1410:    <a href="#response-entity-body">response entity body</a>.</li>
                   1411: 
                   1412:    <li><p>Switch the state to <a href="#dom-xmlhttprequest-done" title="dom-XMLHttpRequest-DONE">DONE</a>.</li>
1.341     avankest 1413: 
1.343     avankest 1414:    <li><p><a class="external" href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-event-fire" title="concept-event-fire">Fire an event</a> named <code title="event-xhr-readystatechange">readystatechange</code>.</li>
1.257     avankest 1415: 
1.343     avankest 1416:    
1.218     avankest 1417:   </ol>
                   1418: 
1.343     avankest 1419:   
                   1420: 
1.280     avankest 1421: 
1.343     avankest 1422:   <h4 id="the-abort-method"><span class="secno">4.6.5 </span>The <code title="">abort()</code> method</h4>
1.341     avankest 1423: 
1.343     avankest 1424:   <dl class="domintro">
                   1425:    <dt><var title="">client</var> . <code title="dom-XMLHttpRequest-abort"><a href="#dom-xmlhttprequest-abort">abort()</a></code></dt>
                   1426:    <dd>Cancels any network activity.</dd>
1.280     avankest 1427:   </dl>
                   1428: 
1.343     avankest 1429:   <p>When the
                   1430:   <dfn id="dom-xmlhttprequest-abort" title="dom-XMLHttpRequest-abort"><code>abort()</code></dfn>
                   1431:   method is invoked, the user agent must run these steps
                   1432:   (unless otherwise noted). This algorithm can be
                   1433:   <dfn id="terminate-abort" title="terminate abort()">terminated</dfn> by invoking the
                   1434:   <code title="dom-XMLHttpRequest-open"><a href="#dom-xmlhttprequest-open">open()</a></code> method. When it is
                   1435:   <a href="#terminate-abort" title="terminate abort()">terminated</a> the user agent
                   1436:   must terminate the algorithm after finishing the step
                   1437:   it is on.</p>
                   1438: 
                   1439:   <p class="note">The <code title="dom-XMLHttpRequest-abort"><a href="#dom-xmlhttprequest-abort">abort()</a></code>
                   1440:   algorithm can only be terminated by invoking
                   1441:   <code title="dom-XMLHttpRequest-open"><a href="#dom-xmlhttprequest-open">open()</a></code> from an event
                   1442:   handler.</p>
1.205     avankest 1443: 
                   1444:   <ol>
1.343     avankest 1445:    <li><p><a href="#terminate-send" title="terminate send()">Terminate the <code>send()</code> algorithm</a>.</li>
1.202     avankest 1446: 
1.343     avankest 1447:    <li><p>The user agent should cancel any network
                   1448:    activity for which the object is responsible.</li>
1.254     avankest 1449: 
1.343     avankest 1450:    <li><p>If there are any
1.346     avankest 1451:    <a class="external" href="http://www.whatwg.org/specs/web-apps/current-work/multipage/webappapis.html#concept-task" title="concept-task">tasks</a> from the
1.343     avankest 1452:    object's <a href="#xmlhttprequest-task-source"><code>XMLHttpRequest</code> task source</a> in one of
1.346     avankest 1453:    the <a class="external" href="http://www.whatwg.org/specs/web-apps/current-work/multipage/webappapis.html#task-queue" title="task queue">task queues</a>,
1.343     avankest 1454:    then remove them.
1.205     avankest 1455: 
1.343     avankest 1456:    <li><p>Set the <a href="#error-flag">error flag</a> to true.</li>
1.205     avankest 1457: 
                   1458:    <li>
1.343     avankest 1459:     <p>If the state is <a href="#dom-xmlhttprequest-unsent" title="dom-XMLHttpRequest-UNSENT">UNSENT</a>,
                   1460:     <a href="#dom-xmlhttprequest-opened" title="dom-XMLHttpRequest-OPENED">OPENED</a> with the
                   1461:     <a href="#send-flag"><code>send()</code> flag</a> being false, or
                   1462:     <a href="#dom-xmlhttprequest-done" title="dom-XMLHttpRequest-DONE">DONE</a> go to the next step.</p>
1.205     avankest 1463: 
                   1464:     <p>Otherwise run these substeps:</p>
                   1465: 
                   1466:     <ol>
1.343     avankest 1467:      <li><p>Switch the state to <a href="#dom-xmlhttprequest-done" title="dom-XMLHttpRequest-DONE">DONE</a>.</li>
                   1468: 
                   1469:      <li><p>Set the <a href="#send-flag"><code>send()</code> flag</a> to false.</li>
1.341     avankest 1470: 
1.343     avankest 1471:      <li><p><a class="external" href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#concept-event-fire" title="concept-event-fire">Fire an event</a> named <code title="event-xhr-readystatechange">readystatechange</code>.</li>
1.77      avankest 1472: 
1.343     avankest 1473:      
1.60      avankest 1474:     </ol>
1.17      avankest 1475: 
1.343     avankest 1476:     
                   1477:     <p class="note">A future version of this specification will dispatch an
                   1478:     <code title="event-xhr-abort">abort</code> event here.</p>
                   1479:     
                   1480:    </li>
1.220     avankest 1481: 
1.205     avankest 1482:    <li>
1.343     avankest 1483:     <p>Switch the state to <a href="#dom-xmlhttprequest-unsent" title="dom-XMLHttpRequest-UNSENT">UNSENT</a>.</p>
1.205     avankest 1484: 
1.343     avankest 1485:     <p class="note">No <code title="event-xhr-readystatechange">readystatechange</code> event is dispatched.</p>
                   1486:    </li>
1.205     avankest 1487:   </ol>
                   1488: 
                   1489: 
                   1490: 
1.343     avankest 1491:   <h3 id="response"><span class="secno">4.7 </span>Response</h3>
                   1492: 
                   1493:   <h4 id="the-status-attribute"><span class="secno">4.7.1 </span>The <code title="">status</code> attribute</h4>
1.341     avankest 1494: 
1.343     avankest 1495:   <dl class="domintro">
                   1496:    <dt><var title="">client</var> . <code title="dom-XMLHttpRequest-status"><a href="#dom-xmlhttprequest-status">status</a></code></dt>
                   1497:    <dd><p>Returns the HTTP status code.</dd>
1.281     avankest 1498:   </dl>
                   1499: 
1.343     avankest 1500:   <p>The
                   1501:   <dfn id="dom-xmlhttprequest-status" title="dom-XMLHttpRequest-status"><code>status</code></dfn>
                   1502:   attribute must return the result of running these
                   1503:   steps:</p>
1.224     avankest 1504: 
                   1505:   <ol>
1.343     avankest 1506:    <li><p>If the state is <a href="#dom-xmlhttprequest-unsent" title="dom-XMLHttpRequest-UNSENT">UNSENT</a> or
                   1507:    <a href="#dom-xmlhttprequest-opened" title="dom-XMLHttpRequest-OPENED">OPENED</a> return 0 and terminate these
                   1508:    steps.</li>
1.224     avankest 1509: 
1.343     avankest 1510:    <li><p>If the <a href="#error-flag">error flag</a> is true return 0 and terminate
                   1511:    these steps.</li>
1.224     avankest 1512: 
1.343     avankest 1513:    <li><p>Return the HTTP status code.</li>
1.224     avankest 1514:   </ol>
1.205     avankest 1515: 
                   1516: 
1.343     avankest 1517:   <h4 id="the-statustext-attribute"><span class="secno">4.7.2 </span>The <code title="">statusText</code> attribute</h4>
1.281     avankest 1518: 
1.343     avankest 1519:   <dl class="domintro">
                   1520:    <dt><var title="">client</var> . <code title="dom-XMLHttpRequest-statusText"><a href="#dom-xmlhttprequest-statustext">statusText</a></code></dt>
                   1521:    <dd><p>Returns the HTTP status text.</dd>
1.281     avankest 1522:   </dl>
                   1523: 
1.343     avankest 1524:   <p>The
                   1525:   <dfn id="dom-xmlhttprequest-statustext" title="dom-XMLHttpRequest-statusText"><code>statusText</code></dfn>
                   1526:   attribute must return the result of running these
                   1527:   steps:</p>
1.224     avankest 1528: 
                   1529:   <ol>
1.343     avankest 1530:    <li><p>If the state is <a href="#dom-xmlhttprequest-unsent" title="dom-XMLHttpRequest-UNSENT">UNSENT</a> or
                   1531:    <a href="#dom-xmlhttprequest-opened" title="dom-XMLHttpRequest-OPENED">OPENED</a> return the empty string and
                   1532:    terminate these steps.</li>
1.224     avankest 1533: 
1.343     avankest 1534:    <li><p>If the <a href="#error-flag">error flag</a> is true return the empty string and
                   1535:    terminate these steps.</li>
1.224     avankest 1536: 
1.343     avankest 1537:    <li><p>Return the HTTP status text.</li>
1.224     avankest 1538:   </ol>
1.205     avankest 1539: 
                   1540: 
1.343     avankest 1541:   <h4 id="the-getresponseheader-method"><span class="secno">4.7.3 </span>The <code title="">getResponseHeader()</code> method</h4>
1.283     avankest 1542: 
1.343     avankest 1543:   <dl class="domintro">
                   1544:    <dt><var title="">client</var> . <code title="dom-XMLHttpRequest-getResponseHeader"><a href="#dom-xmlhttprequest-getresponseheader">getResponseHeader(<var title="">header</var>)</a></code></dt>
                   1545:    <dd><p>Returns the header field value from the response of which the
                   1546:    field name matches <var title="">header</var>, unless the field name is
                   1547:    <code>Set-Cookie</code> or <code>Set-Cookie2</code>.</p>
1.283     avankest 1548:   </dl>
                   1549: 
1.343     avankest 1550:   <p>When the
                   1551:   <dfn id="dom-xmlhttprequest-getresponseheader" title="dom-XMLHttpRequest-getResponseHeader"><code>getResponseHeader(<var title="">header</var>)</code></dfn>
                   1552:   is invoked, the user agent must run these steps:</p>
1.205     avankest 1553: 
                   1554:   <ol>
1.343     avankest 1555:    <li><p>If the state is <a href="#dom-xmlhttprequest-unsent" title="dom-XMLHttpRequest-UNSENT">UNSENT</a> or
                   1556:    <a href="#dom-xmlhttprequest-opened" title="dom-XMLHttpRequest-OPENED">OPENED</a> return null and terminate these
                   1557:    steps.</li>
                   1558: 
                   1559:    <li><p>If the <a href="#error-flag">error flag</a> is true return null
                   1560:    and terminate these steps.</li>
                   1561: 
                   1562:    <li><p>If any code point in <var>header</var> is higher than
                   1563:    U+00FF LATIN SMALL LETTER Y WITH DIAERESIS return null and terminate
                   1564:    these steps.</li>
                   1565: 
                   1566:    <li><p>Let <var>header</var> be the result of
                   1567:    <a href="#deflate-a-domstring-into-a-byte-sequence" title="deflate a DOMString into a byte sequence">deflating</a>
                   1568:    <var>header</var>.</li> <!-- This sounds lame, but it works. -->
                   1569: 
                   1570:    <li><p>If <var>header</var> is a case-insensitive match for
                   1571:    <code>Set-Cookie</code> or <code>Set-Cookie2</code> return null and
                   1572:    terminate these steps.</li>
                   1573: 
                   1574:    <li><p>If <var>header</var> is a case-insensitive match for multiple HTTP
                   1575:    response headers, return the
                   1576:    <a href="#inflate-a-byte-sequence-into-a-domstring" title="inflate a byte sequence into a DOMString">inflated</a>
                   1577:    values of these headers as a single concatenated string separated from
                   1578:    each other by a U+002C COMMA U+0020 SPACE character pair and terminate
                   1579:    these steps.</li>
                   1580: 
                   1581:    <li><p>If <var>header</var> is a case-insensitive match for a single HTTP
                   1582:    response header, return the
                   1583:    <a href="#inflate-a-byte-sequence-into-a-domstring" title="inflate a byte sequence into a DOMString">inflated</a>
                   1584:    value of that header and terminate these steps.</li>
1.342     avankest 1585: 
1.343     avankest 1586:    <li><p>Return null.</li>
                   1587:   </ol>
1.342     avankest 1588: 
1.343     avankest 1589:   
1.342     avankest 1590: 
1.343     avankest 1591:   <div class="example">
1.342     avankest 1592: 
1.252     avankest 1593:    <p>For the following script:</p>
                   1594: 
                   1595:    <pre><code>var client = new XMLHttpRequest();
                   1596: client.open("GET", "unicorns-are-teh-awesome.txt", true);
1.6       avankest 1597: client.send();
1.16      avankest 1598: client.onreadystatechange = function() {
1.252     avankest 1599:   if(this.readyState == 2) {
                   1600:     print(client.getResponseHeader("Content-Type"));
                   1601:   }
                   1602: }</code></pre>
                   1603: 
1.343     avankest 1604:    <p>The <code>print()</code> function will get to process something
                   1605:    like:</p>
1.1       avankest 1606: 
1.252     avankest 1607:    <pre><code>text/plain; charset=UTF-8</code></pre>
1.205     avankest 1608:   </div>
                   1609: 
1.2       avankest 1610: 
1.343     avankest 1611:   <h4 id="the-getallresponseheaders-method"><span class="secno">4.7.4 </span>The <code title="">getAllResponseHeaders()</code> method</h4>
1.283     avankest 1612: 
1.343     avankest 1613:   <dl class="domintro">
                   1614:    <dt><var title="">client</var> . <code title="dom-XMLHttpRequest-getAllResponseHeaders"><a href="#dom-xmlhttprequest-getallresponseheaders">getAllResponseHeaders()</a></code></dt>
                   1615:    <dd><p>Returns all headers from the response, with the exception of those
                   1616:    whose field name is <code>Set-Cookie</code> or
                   1617:    <code>Set-Cookie2</code>.</dd>
1.283     avankest 1618:   </dl>
                   1619: 
1.343     avankest 1620:   <p>When the
                   1621:   <dfn id="dom-xmlhttprequest-getallresponseheaders" title="dom-XMLHttpRequest-getAllResponseHeaders"><code>getAllResponseHeaders()</code></dfn>
                   1622:   method is invoked, the user agent must run these steps:</p>
1.6       avankest 1623: 
1.205     avankest 1624:   <ol>
1.343     avankest 1625:    <li><p>If the state is <a href="#dom-xmlhttprequest-unsent" title="dom-XMLHttpRequest-UNSENT">UNSENT</a> or
                   1626:    <a href="#dom-xmlhttprequest-opened" title="dom-XMLHttpRequest-OPENED">OPENED</a> return the empty string and
                   1627:    terminate these steps.</li>
                   1628: 
                   1629:    <li><p>If the <a href="#error-flag">error flag</a> is true return the empty string and
                   1630:    terminate these steps.</li>
                   1631: 
                   1632:    <li><p>Return all the HTTP headers, excluding headers that are a
                   1633:    case-insensitive match for <code>Set-Cookie</code> or
                   1634:    <code>Set-Cookie2</code>,
                   1635:    <a href="#inflate-a-byte-sequence-into-a-domstring" title="inflate a byte sequence into a DOMString">inflated</a>,
                   1636:    as a single string, with each header line
                   1637:    separated by a U+000D CR U+000A LF pair, excluding the status line, and
                   1638:    with each header name and header value separated by a
                   1639:    U+003A COLON U+0020 SPACE pair.</li>
                   1640:   </ol>
1.342     avankest 1641: 
1.343     avankest 1642:   
1.205     avankest 1643: 
1.343     avankest 1644:   <div class="example">
1.252     avankest 1645:    <p>For the following script:</p>
                   1646: 
                   1647:    <pre><code>var client = new XMLHttpRequest();
                   1648: client.open("GET", "narwhals-too.txt", true);
1.205     avankest 1649: client.send();
                   1650: client.onreadystatechange = function() {
1.312     avankest 1651:   if(this.readyState == 2) {
                   1652:     print(this.getAllResponseHeaders());
                   1653:   }
1.252     avankest 1654: }</code></pre>
                   1655: 
1.343     avankest 1656:    <p>The <code>print()</code> function will get to process something
                   1657:    like:</p>
1.205     avankest 1658: 
1.252     avankest 1659:    <pre><code>Date: Sun, 24 Oct 2004 04:58:38 GMT
1.205     avankest 1660: Server: Apache/1.3.31 (Unix)
                   1661: Keep-Alive: timeout=15, max=99
                   1662: Connection: Keep-Alive
                   1663: Transfer-Encoding: chunked
                   1664: Content-Type: text/plain; charset=utf-8</code></pre>
                   1665:   </div>
                   1666: 
1.250     avankest 1667: 
1.343     avankest 1668: 
1.348     avankest 1669:   <h4 id="response-entity-body-0"><span class="secno">4.7.5 </span>Response entity body</h4>
1.343     avankest 1670: 
                   1671:   <p>The <dfn id="response-mime-type">response MIME type</dfn> is the MIME
                   1672:   type the <code>Content-Type</code> header contains without any
                   1673:   parameters or null if the header could not be parsed properly or was
                   1674:   omitted. The <dfn id="override-mime-type">override MIME type</dfn> is
                   1675:   always null. <dfn id="final-mime-type">Final MIME type</dfn> is the
                   1676:   override MIME type unless that is null in which case it is the response
                   1677:   MIME type.</p>
                   1678: 
                   1679:   <p>The <dfn id="response-charset">response charset</dfn> is the value of
                   1680:   the <code>charset</code> parameter of the <code>Content-Type</code> header
                   1681:   or null if there was no <code>charset</code> parameter or if
                   1682:   the header could not be parsed properly or was omitted. The
                   1683:   <dfn id="override-charset">override charset</dfn> is always null.
                   1684:   <dfn id="final-charset">Final charset</dfn> is the override charset unless
                   1685:   that is null in which case it is the response charset.</p>
                   1686: 
                   1687:   
                   1688:   <p class="note"><a href="#override-mime-type">Override MIME type</a> and
                   1689:   <a href="#override-charset">override charset</a> are introduced here solely to make editing
                   1690:   several levels of XMLHttpRequest simultaneously somewhat easier. Apologies
                   1691:   for any confusion they might cause.</p>
                   1692:   
1.250     avankest 1693: 
                   1694:   <hr>
1.205     avankest 1695: 
1.343     avankest 1696:   <p>The <dfn id="response-entity-body">response entity body</dfn> is the
                   1697:   fragment of the <a class="external" href="http://tools.ietf.org/html/rfc2616/#section-7.2">entity body</a> of the
                   1698:   response received so far
                   1699:   (<a href="#dom-xmlhttprequest-loading" title="dom-XMLHttpRequest-LOADING">LOADING</a>) or the complete
                   1700:   entity body of the response
                   1701:   (<a href="#dom-xmlhttprequest-done" title="dom-XMLHttpRequest-DONE">DONE</a>). If the response
                   1702:   does not have an entity body the response entity body is null.</p>
                   1703: 
                   1704:   <p class="note">The <a href="#response-entity-body">response entity body</a> is updated as part
                   1705:   of the <code title="dom-XMLHttpRequest-send"><a href="#dom-xmlhttprequest-send">send()</a></code> algorithm.</p>
1.205     avankest 1706: 
                   1707:   <hr>
                   1708: 
1.343     avankest 1709:   <p>The <dfn id="text-response-entity-body">text response entity body</dfn>
                   1710:   is a <code>DOMString</code> representing the <a href="#response-entity-body">response entity
                   1711:   body</a>. The text response entity body is the return value of the
                   1712:   following algorithm:</p>
1.205     avankest 1713: 
                   1714:   <ol>
1.343     avankest 1715:    <li><p>If the response entity body is null return the empty string and
                   1716:    terminate these steps.</p>
1.250     avankest 1717: 
1.343     avankest 1718:    <li><p>Let <var>charset</var> be the <a href="#final-charset">final charset</a>.</li>
1.205     avankest 1719: 
1.343     avankest 1720:    <li><p>Let <var>mime</var> be the <a href="#final-mime-type">final MIME type</a>.</li>
1.205     avankest 1721: 
1.343     avankest 1722:    <li><p>If <var>charset</var> is null and <var>mime</var> is null,
                   1723:    <code>text/xml</code>, <code>application/xml</code> or ends in
                   1724:    <code title="">+xml</code> use the rules set forth in the XML
                   1725:    specifications to determine the character encoding. Let
                   1726:    <var>charset</var> be the determined character encoding.</li>
                   1727: 
                   1728:    <li><p>If <var>charset</var> is null and <var>mime</var> is
                   1729:    <code>text/html</code> follow the rules set forth in the HTML
                   1730:    specification to determine the character encoding. Let
                   1731:    <var>charset</var> be the determined character encoding.
                   1732:    <a href="#refsHTML">[HTML]</a>
1.205     avankest 1733: 
                   1734:    <li>
                   1735:     <p>If <var>charset</var> is null then, for each of the rows in the
1.343     avankest 1736:     following table, starting with the first one and going down, if the first
                   1737:     bytes of <var>bytes</var> match the bytes given in the first column, then
                   1738:     let <var>charset</var> be the encoding given in the cell in the second
                   1739:     column of that row. If there is no match <var>charset</var> remains
                   1740:     null.</p>
1.205     avankest 1741: 
                   1742:     <table>
                   1743:      <thead>
                   1744:       <tr>
                   1745:        <th>Bytes in Hexadecimal
                   1746:        <th>Description
1.239     avankest 1747:      <tbody>
1.205     avankest 1748:       <tr>
                   1749:        <td>FE FF
                   1750:        <td>UTF-16BE BOM
                   1751:       <tr>
                   1752:        <td>FF FE
                   1753:        <td>UTF-16LE BOM
                   1754:       <tr>
                   1755:        <td>EF BB BF
1.239     avankest 1756:        <td>UTF-8 BOM
1.205     avankest 1757:     </table>
1.343     avankest 1758:    </li>
1.205     avankest 1759: 
1.343     avankest 1760:    <li><p>If <var>charset</var> is null let <var>charset</var> be
                   1761:    UTF-8.</li>
1.205     avankest 1762: 
1.343     avankest 1763:    <li><p>Return the result of decoding the response entity body using
                   1764:    <var>charset</var>. Replace bytes or sequences of bytes that are not
                   1765:    valid accordng to the <var>charset</var> with a single
                   1766:    U+FFFD REPLACEMENT CHARACTER character. Remove one leading
                   1767:    U+FEFF BYTE ORDER MARK character, if present.</li>
1.205     avankest 1768:   </ol>
                   1769: 
1.343     avankest 1770:   <p class="note">Authors are strongly encouraged to always encode their
                   1771:   resources using UTF-8.</p>
1.205     avankest 1772: 
                   1773:   <hr>
                   1774: 
1.343     avankest 1775:   <p>The <dfn id="document-response-entity-body">document response entity
                   1776:   body</dfn> is either a <code class="external"><a href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#document">Document</a></code> representing the
                   1777:   <a href="#response-entity-body">response entity body</a> or null. If it is a
1.346     avankest 1778:   <code class="external"><a href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#document">Document</a></code> its <a class="external" href="http://www.whatwg.org/specs/web-apps/current-work/multipage/origin-0.html#origin">origin</a> is the
1.343     avankest 1779:   <a href="#xmlhttprequest-origin"><code>XMLHttpRequest</code> origin</a>. If the
                   1780:   <a href="#document-response-entity-body">document response entity body</a> has no value assigned to it let
                   1781:   it be the return value of the following algorithm:</p>
1.89      avankest 1782: 
1.205     avankest 1783:   <ol>
1.343     avankest 1784:    <li><p>If the <a href="#response-entity-body">response entity body</a> is null, return null and
                   1785:    terminate these steps.</li>
1.342     avankest 1786: 
1.343     avankest 1787:    <li><p>If <a href="#final-mime-type">final MIME type</a> is not null,
                   1788:    <code>text/xml</code>,
                   1789:    <code>application/xml</code>, or does not end in
                   1790:    <code title="">+xml</code>, return null and terminate these
                   1791:    steps.</li>
                   1792: 
                   1793:    
                   1794: 
                   1795:    <li>
                   1796:     <p>Let <var title="">document</var> be a
                   1797:     <code class="external"><a href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#document">Document</a></code> object that represents the result of parsing the
                   1798:     <a href="#response-entity-body">response entity body</a> into a document tree following the
                   1799:     rules set forth in the XML specifications. If that fails
                   1800:     (unsupported character encoding, namespace well-formedness error et
                   1801:     cetera) return null and terminate these steps.
                   1802:     <a href="#refsXML">[XML]</a> <a href="#refsXMLNS">[XMLNS]</a>
                   1803: 
                   1804:     <p class="note">Scripts in the resulting document tree will not be executed,
                   1805:     resources referenced will not be loaded and no associated XSLT will be
                   1806:     applied.</p> <!-- XXX more formally?! -->
                   1807:    </li>
1.6       avankest 1808: 
1.343     avankest 1809:    <li><p>Return <var title="">document</var>.</li>
                   1810:   </ol>
1.12      avankest 1811: 
1.343     avankest 1812:   
1.76      avankest 1813: 
1.12      avankest 1814: 
1.343     avankest 1815:   <h4 id="the-responsetext-attribute"><span class="secno">4.7.6 </span>The <code title="">responseText</code> attribute</h4>
1.281     avankest 1816: 
1.343     avankest 1817:   <dl class="domintro">
                   1818:    <dt><var title="">client</var> . <code title="dom-XMLHttpRequest-responseText"><a href="#dom-xmlhttprequest-responsetext">responseText</a></code></dt>
1.281     avankest 1819:    <dd>
1.343     avankest 1820:     <p>Returns the <a href="#text-response-entity-body">text response entity body</a>.</p>
                   1821:     
                   1822:    </dd>
1.281     avankest 1823:   </dl>
                   1824: 
1.343     avankest 1825:   <p>The
                   1826:   <dfn id="dom-xmlhttprequest-responsetext" title="dom-XMLHttpRequest-responseText"><code>responseText</code></dfn>
                   1827:   attribute must return the result of running these
                   1828:   steps:</p>
1.6       avankest 1829: 
1.205     avankest 1830:   <ol>
1.343     avankest 1831:    
                   1832: 
                   1833:    <li><p>If the state is not <a href="#dom-xmlhttprequest-loading" title="dom-XMLHttpRequest-LOADING">LOADING</a> or
                   1834:    <a href="#dom-xmlhttprequest-done" title="dom-XMLHttpRequest-DONE">DONE</a> return the empty string and
                   1835:    terminate these steps.</li>
1.341     avankest 1836: 
1.343     avankest 1837:    <li><p>If the <a href="#error-flag">error flag</a> is true return the empty string and
                   1838:    terminate these steps.</li>
1.12      avankest 1839: 
1.343     avankest 1840:    <li><p>Return the <a href="#text-response-entity-body">text response entity body</a>.</li>
1.205     avankest 1841:   </ol>
1.2       avankest 1842: 
                   1843: 
1.343     avankest 1844:   <h4 id="the-responsexml-attribute"><span class="secno">4.7.7 </span>The <code title="">responseXML</code> attribute</h4>
1.281     avankest 1845: 
1.343     avankest 1846:   <dl class="domintro">
                   1847:    <dt><var title="">client</var> . <code title="dom-XMLHttpRequest-responseXML"><a href="#dom-xmlhttprequest-responsexml">responseXML</a></code></dt>
1.281     avankest 1848:    <dd>
1.343     avankest 1849:     <p>Returns the <a href="#document-response-entity-body">document response entity body</a>.</p>
                   1850:     
                   1851:    </dd>
1.281     avankest 1852:   </dl>
                   1853: 
1.343     avankest 1854:   <p>The
                   1855:   <dfn id="dom-xmlhttprequest-responsexml" title="dom-XMLHttpRequest-responseXML"><code>responseXML</code></dfn>
1.344     avankest 1856:   attribute must return the result of running these steps:</p>
1.2       avankest 1857: 
1.205     avankest 1858:   <ol>
1.343     avankest 1859:    
                   1860: 
                   1861:    <li><p>If the state is not <a href="#dom-xmlhttprequest-done" title="dom-XMLHttpRequest-DONE">DONE</a> return
                   1862:    null and terminate these steps.</li>
1.342     avankest 1863: 
1.343     avankest 1864:    <li><p>If the <a href="#error-flag">error flag</a> is true return null and terminate
                   1865:    these steps.</li>
1.341     avankest 1866: 
1.343     avankest 1867:    <li><p>Return the <a href="#document-response-entity-body">document response entity body</a>.</li>
1.342     avankest 1868:   </ol>
1.2       avankest 1869: 
1.343     avankest 1870:   
1.2       avankest 1871: 
1.18      avankest 1872: 
1.343     avankest 1873: <h2 class="no-num" id="references">References</h2>
                   1874: <h3 class="no-num" id="normative-references">Normative references</h3>
                   1875: <div id="anolis-references-normative"><dl><dt id="refsCOOKIES">[COOKIES]
1.346     avankest 1876: <dd><cite><a href="http://tools.ietf.org/html/rfc6265">HTTP State Management Mechanism</a></cite>, Adam Barth. IETF.
1.343     avankest 1877: 
                   1878: <dt id="refsDOMCORE">[DOMCORE]
1.346     avankest 1879: <dd><cite><a href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html">DOM Core</a></cite>, Anne van Kesteren and Ms2ger. W3C.
1.343     avankest 1880: 
                   1881: <dt id="refsFILEAPI">[FILEAPI]
1.346     avankest 1882: <dd><cite><a href="http://dev.w3.org/2006/webapi/FileAPI/">File API</a></cite>, Arun Ranganathan and Jonas Sicking. W3C.
1.343     avankest 1883: 
                   1884: <dt id="refsHTML">[HTML]
1.346     avankest 1885: <dd><cite><a href="http://www.whatwg.org/html">HTML</a></cite>, Ian Hickson. WHATWG.
1.343     avankest 1886: 
                   1887: <dt id="refsHTTP">[HTTP]
1.347     avankest 1888: <dd><cite><a href="http://tools.ietf.org/html/rfc2616">Hypertext Transfer Protocol -- HTTP/1.1</a></cite>, Roy Fielding, James Gettys, Jeffrey Mogul et al.. IETF.
1.343     avankest 1889: 
                   1890: <dt id="refsHTTPAUTH">[HTTPAUTH]
1.347     avankest 1891: <dd><cite><a href="http://tools.ietf.org/html/rfc2617">HTTP Authentication: Basic and Digest Access Authentication</a></cite>, J. Franks, Phillip Hallam-Baker, J. Hostetler et al.. IETF.
1.343     avankest 1892: 
                   1893: <dt id="refsHTTPVERBSEC">[HTTPVERBSEC]
                   1894: <dd><cite><a href="http://www.kb.cert.org/vuls/id/867593">Multiple vendors' web servers enable HTTP TRACE method by default</a></cite>. US-CERT.
                   1895: 
                   1896: <dd><cite><a href="http://www.kb.cert.org/vuls/id/288308">Microsoft Internet Information Server (IIS) vulnerable to cross-site scripting via HTTP TRACK method</a></cite>. US-CERT.
                   1897: 
                   1898: <dd><cite><a href="http://www.kb.cert.org/vuls/id/150227">HTTP proxy default configurations allow arbitrary TCP connections</a></cite>. US-CERT.
                   1899: 
                   1900: <dt id="refsRFC2119">[RFC2119]
1.346     avankest 1901: <dd><cite><a href="http://tools.ietf.org/html/rfc2119">Key words for use in RFCs to Indicate Requirement Levels</a></cite>, Scott Bradner. IETF.
1.343     avankest 1902: 
                   1903: <dt id="refsWEBIDL">[WEBIDL]
1.346     avankest 1904: <dd><cite><a href="http://dev.w3.org/2006/webapi/WebIDL/">Web IDL</a></cite>, Cameron McCormack. W3C.
1.343     avankest 1905: 
                   1906: <dt id="refsXML">[XML]
1.346     avankest 1907: <dd><cite><a href="http://www.w3.org/TR/xml/">Extensible Markup Language</a></cite>, Tim Bray, Jean Paoli, C. M. Sperberg-McQueen et al.. W3C.
1.343     avankest 1908: 
                   1909: <dt id="refsXMLNS">[XMLNS]
1.346     avankest 1910: <dd><cite><a href="http://www.w3.org/TR/xml-names/">Namespaces in XML</a></cite>, Tim Bray, Dave Hollander, Andrew Layman et al.. W3C.
1.343     avankest 1911: 
                   1912: </dl></div>
                   1913: 
                   1914: <h3 class="no-num" id="informative-references">Informative references</h3>
                   1915: <div id="anolis-references-informative"><dl><dt id="refsECMASCRIPT">[ECMASCRIPT]
                   1916: <dd><cite><a href="http://www.ecma-international.org/publications/standards/Ecma-262.htm">ECMAScript Language Specification</a></cite>. ECMA.
                   1917: 
                   1918: </dl></div>
                   1919: 
                   1920: 
                   1921: 
                   1922:   <h2 class="no-num" id="acknowledgments">Acknowledgments</h2>
                   1923: 
                   1924:   <p>The editor would like to thank
                   1925: 
                   1926:   Addison Phillips,
                   1927:   Ahmed Kamel,
                   1928:   Alex Hopmann,
                   1929:   Alex Vincent,
                   1930:   Alexey Proskuryakov,
                   1931:   Asbj&oslash;rn Ulsberg,
                   1932:   Boris Zbarsky,
                   1933:   Bj&ouml;rn H&ouml;hrmann,
                   1934:   Cameron McCormack,
                   1935:   Chris Marrin,
                   1936:   Christophe Jolif,
                   1937:   Charles McCathieNevile,
                   1938:   Dan Winship,
                   1939:   David Andersson,
                   1940:   David Flanagan,
                   1941:   David H&aring;s&auml;ther,
                   1942:   David Levin,
                   1943:   Dean Jackson,
                   1944:   Denis Sureau,
                   1945:   Doug Schepers,
                   1946:   Douglas Livingstone,
                   1947:   Elliotte Harold,
                   1948:   Eric Lawrence,
                   1949:   Eric Uhrhane,
                   1950:   Erik Dahlstr&ouml;m,
                   1951:   Geoffrey Sneddon,
                   1952:   Gideon Cohn,
                   1953:   Gorm Haug Eriksen,
                   1954:   H&aring;kon Wium Lie,
                   1955:   Hallvord R. M. Steen,
                   1956:   Henri Sivonen,
                   1957:   Huub Schaeks,
                   1958:   Ian Davis,
                   1959:   Ian Hickson,
                   1960:   Ivan Herman,
                   1961:   Jeff Walden,
                   1962:   Jens Lindstr&ouml;m,
                   1963:   Jim Deegan,
                   1964:   Jim Ley,
                   1965:   Joe Farro,
                   1966:   Jonas Sicking,
                   1967:   Julian Reschke,
                   1968:   Karl Dubost,
                   1969:   Lachlan Hunt,
                   1970:   Maciej Stachowiak,
                   1971:   Magnus Kristiansen,
                   1972:   Marc Hadley,
                   1973:   Marcos Caceres,
                   1974:   Mark Baker,
                   1975:   Mark Birbeck,
                   1976:   Mark Nottingham,
                   1977:   Mark S. Miller,
                   1978:   Martin Hassman,
                   1979:   Mohamed Zergaoui,
                   1980:   Olli Pettay,
                   1981:   Pawel Glowacki,
                   1982:   Peter Michaux,
                   1983:   Philip Taylor,
                   1984:   Robin Berjon,
                   1985:   Rune Halvorsen,
                   1986:   Ruud Steltenpool,
                   1987:   Sergiu Dumitriu,
                   1988:   Simon Pieters,
                   1989:   Stewart Brodie,
                   1990:   Sunava Dutta,
                   1991:   Thomas Roessler,
                   1992:   Tom Magliery, and
                   1993:   Zhenbin Xu
                   1994: 
                   1995:   for their contributions to this specification.</p>
                   1996: 
                   1997:   <p>Special thanks to the Microsoft employees who first implemented the
                   1998:   <code title="">XMLHttpRequest</code> interface, which was first widely
                   1999:   deployed by the Windows Internet Explorer browser.</p>
1.2       avankest 2000: 
1.56      avankest 2001:   <p>Special thanks also to the WHATWG for drafting an initial version of
1.343     avankest 2002:   this specification in their Web Applications 1.0 document (now renamed to
                   2003:   HTML). <a href="#refsHTML">[HTML]</a></p>
1.2       avankest 2004: 
                   2005:   <p>Thanks also to all those who have helped to improve this specification
1.343     avankest 2006:   by sending suggestions and corrections. (Please, keep bugging us with your
                   2007:   issues!)</p>
                   2008:  
                   2009: 

Webmaster