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

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

Webmaster