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

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

Webmaster