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

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

Webmaster