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

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

Webmaster