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

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

Webmaster