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

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>
                      5:   <title>The XMLHttpRequest Object</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.90      avankest   14:    .issue { padding:.5em; border:solid #f00 }
1.20      avankest   15:    p.issue::before { content:"Issue: " }
1.120     avankest   16:    dl.switch { padding-left:2em }
                     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.20      avankest   19:    em.ct { text-transform:lowercase; font-variant:small-caps; font-style:normal }
                     20:    dfn { font-weight:bold; font-style:normal }
                     21:    code { color:orangered }
                     22:    code :link, code :visited { color:inherit }
1.123     avankest   23:    h1 code, h2 code, h3 code { color:inherit; background:inherit; font:inherit }
1.20      avankest   24:   </style>
1.25      avankest   25:   <link href="http://www.w3.org/StyleSheets/TR/base" rel=stylesheet>
1.121     avankest   26:   <link href="http://www.w3.org/StyleSheets/TR/W3C-WD" rel=stylesheet>
1.2       avankest   27: 
1.1       avankest   28:  <body>
1.25      avankest   29:   <div class=head>
                     30:    <p><a href="http://www.w3.org/"><img alt=W3C height=48
                     31:     src="http://www.w3.org/Icons/w3c_home" width=72></a></p>
1.2       avankest   32: 
1.25      avankest   33:    <h1 class=head id=the-xmlhttprequest>The <code
1.14      avankest   34:     title="">XMLHttpRequest</code> Object</h1>
1.2       avankest   35: 
1.128     avankest   36:    <h2 class="no-num no-toc" id=pagesubtitle>Editor's
                     37:     draft<!--W3C Working Draft--> 25 July 2007</h2>
1.2       avankest   38: 
1.1       avankest   39:    <dl>
1.14      avankest   40:     <dt>This Version:
1.2       avankest   41: 
                     42:     <dd><a
1.128     avankest   43:      href="http://www.w3.org/TR/2007/WD-XMLHttpRequest-20070725/">http://www.w3.org/TR/2007/WD-XMLHttpRequest-20070725/</a>
1.2       avankest   44: 
1.14      avankest   45:     <dt>Latest Version:
1.2       avankest   46: 
                     47:     <dd><a
                     48:      href="http://www.w3.org/TR/XMLHttpRequest/">http://www.w3.org/TR/XMLHttpRequest/</a>
                     49: 
1.14      avankest   50:     <dt>Previous Versions:
1.2       avankest   51: 
                     52:     <dd><a
1.134   ! avankest   53:      href="http://www.w3.org/TR/2007/WD-XMLHttpRequest-20070618/">http://www.w3.org/TR/2007/WD-XMLHttpRequest-20070618/</a>
        !            54: 
        !            55:     <dd><a
1.60      avankest   56:      href="http://www.w3.org/TR/2007/WD-XMLHttpRequest-20070227/">http://www.w3.org/TR/2007/WD-XMLHttpRequest-20070227/</a>
                     57: 
                     58:     <dd><a
1.25      avankest   59:      href="http://www.w3.org/TR/2006/WD-XMLHttpRequest-20060927/">http://www.w3.org/TR/2006/WD-XMLHttpRequest-20060927/</a>
                     60: 
                     61:     <dd><a
1.2       avankest   62:      href="http://www.w3.org/TR/2006/WD-XMLHttpRequest-20060619/">http://www.w3.org/TR/2006/WD-XMLHttpRequest-20060619/</a>
                     63: 
                     64:     <dd><a
                     65:      href="http://www.w3.org/TR/2006/WD-XMLHttpRequest-20060405/">http://www.w3.org/TR/2006/WD-XMLHttpRequest-20060405/</a>
                     66: 
                     67:     <dt>Editor:
                     68: 
                     69:     <dd><a href="http://annevankesteren.nl/">Anne van Kesteren</a> (<a
                     70:      href="http://www.opera.com/">Opera Software ASA</a>) &lt;<a
                     71:      href="mailto:annevk@opera.com">annevk@opera.com</a>&gt;
1.1       avankest   72:    </dl>
1.2       avankest   73: 
1.25      avankest   74:    <p class=copyright><a
1.2       avankest   75:     href="http://www.w3.org/Consortium/Legal/ipr-notice#Copyright">Copyright</a>
1.53      avankest   76:     &copy; 2007 <a href="http://www.w3.org/"><acronym title="World Wide Web
                     77:     Consortium">W3C</acronym></a><sup>&reg;</sup> (<a
                     78:     href="http://www.csail.mit.edu/"><acronym title="Massachusetts Institute
                     79:     of Technology">MIT</acronym></a>, <a
                     80:     href="http://www.ercim.org/"><acronym title="European Research Consortium
                     81:     for Informatics and Mathematics">ERCIM</acronym></a>, <a
1.2       avankest   82:     href="http://www.keio.ac.jp/">Keio</a>), All Rights Reserved. W3C <a
                     83:     href="http://www.w3.org/Consortium/Legal/ipr-notice#Legal_Disclaimer">liability</a>,
                     84:     <a
                     85:     href="http://www.w3.org/Consortium/Legal/ipr-notice#W3C_Trademarks">trademark</a>
                     86:     and <a
                     87:     href="http://www.w3.org/Consortium/Legal/copyright-documents">document
                     88:     use</a> rules apply.</p>
1.1       avankest   89:   </div>
1.2       avankest   90: 
                     91:   <hr>
                     92: 
1.25      avankest   93:   <h2 class="no-num no-toc" id=specabstract>Abstract</h2>
1.2       avankest   94: 
1.25      avankest   95:   <p>The <code title="">XMLHttpRequest</code> Object specification defines an
                     96:    <abbr title="Application Programming Interface">API</abbr> that provides
                     97:    scripted client functionality for transferring data between a client and a
                     98:    server.
                     99: 
                    100:   <h2 class="no-num no-toc" id=sotd>Status of this Document</h2>
1.2       avankest  101: 
                    102:   <p><em>This section describes the status of this document at the time of
                    103:    its publication. Other documents may supersede this document. A list of
                    104:    current W3C publications and the latest revision of this technical report
                    105:    can be found in the <a href="http://www.w3.org/TR/">W3C technical reports
1.65      avankest  106:    index</a> at http://www.w3.org/TR/.</em></p>
                    107:   <!-- change back to Last Call -->
1.2       avankest  108: 
1.128     avankest  109:   <p>This is the 25 July 2007 <strong>Editor's</strong> <!--Working--> Draft
                    110:    of The <code title="">XMLHttpRequest</code> Object specification. Please
                    111:    send comments to <a
1.121     avankest  112:    href="mailto:public-webapi@w3.org">public-webapi@w3.org</a> (<a
1.49      avankest  113:    href="http://lists.w3.org/Archives/Public/public-webapi/">archived</a>)
                    114:    with either <samp>[XHR]</samp> or <samp title="">[XMLHttpRequest]</samp>
1.65      avankest  115:    at the start of the subject line<!-- by 2 April 2007-->.
1.49      avankest  116: 
                    117:   <p>This document is produced by the <a
                    118:    href="http://www.w3.org/2006/webapi/">Web API Working Group</a>, part of
                    119:    the <a href="http://www.w3.org/2006/rwc/Activity">Rich Web Clients
                    120:    Activity</a> in the W3C <a
                    121:    href="http://www.w3.org/Interaction/">Interaction Domain</a>. Changes made
                    122:    to this document can be found in the <a
                    123:    href="http://dev.w3.org/cvsweb/2006/webapi/XMLHttpRequest/Overview.html">W3C
                    124:    public CVS server</a>.
1.2       avankest  125: 
                    126:   <p>Publication as a Working Draft does not imply endorsement by the W3C
                    127:    Membership. This is a draft document and may be updated, replaced or
                    128:    obsoleted by other documents at any time. It is inappropriate to cite this
                    129:    document as other than work in progress.
                    130: 
                    131:   <p>This document was produced by a group operating under the <a
                    132:    href="http://www.w3.org/Consortium/Patent-Policy-20040205/">5 February
1.54      avankest  133:    2004 W3C Patent Policy</a>. W3C maintains a <a
                    134:    href="http://www.w3.org/2004/01/pp-impl/38482/status"
1.25      avankest  135:    rel=disclosure>public list of any patent disclosures</a> made in
1.2       avankest  136:    connection with the deliverables of the group; that page also includes
                    137:    instructions for disclosing a patent. An individual who has actual
                    138:    knowledge of a patent which the individual believes contains <a
                    139:    href="http://www.w3.org/Consortium/Patent-Policy-20040205/#def-essential">Essential
                    140:    Claim(s)</a> must disclose the information in accordance with <a
                    141:    href="http://www.w3.org/Consortium/Patent-Policy-20040205/#sec-Disclosure">section
                    142:    6 of the W3C Patent Policy</a>.
                    143: 
1.25      avankest  144:   <h2 class="no-num no-toc" id=toc>Table of Contents</h2>
1.2       avankest  145:   <!--begin-toc-->
                    146: 
1.25      avankest  147:   <ul class=toc>
                    148:    <li><a href="#introduction"><span class=secno>1. </span>Introduction</a>
                    149:     <ul class=toc>
1.31      avankest  150:      <li><a href="#examples"><span class=secno>1.1. </span>Examples of
1.2       avankest  151:       Usage</a>
                    152: 
1.31      avankest  153:      <li><a href="#conformance"><span class=secno>1.2. </span>Conformance</a>
1.25      avankest  154:       
1.31      avankest  155:       <ul class=toc>
                    156:        <li><a href="#dependencies"><span class=secno>1.2.1.
1.32      avankest  157:         </span>Dependencies</a>
1.81      avankest  158: 
                    159:        <li><a href="#terminology"><span class=secno>1.2.2.
                    160:         </span>Terminology</a>
                    161: 
                    162:        <li><a href="#extensibility"><span class=secno>1.2.3.
                    163:         </span>Extensibility</a>
1.31      avankest  164:       </ul>
1.2       avankest  165:     </ul>
                    166: 
1.25      avankest  167:    <li><a href="#xmlhttprequest"><span class=secno>2. </span>The <code
1.16      avankest  168:     title="">XMLHttpRequest</code> Object</a>
1.25      avankest  169:     <ul class=toc>
1.60      avankest  170:      <li><a href="#events"><span class=secno>2.1. </span>Events for the <code
1.33      avankest  171:       title="">XMLHttpRequest</code> Object</a>
                    172: 
1.60      avankest  173:      <li><a href="#exceptions"><span class=secno>2.2. </span>Exceptions for
1.33      avankest  174:       the <code title="">XMLHttpRequest</code> Object</a>
1.11      avankest  175:     </ul>
1.2       avankest  176: 
1.31      avankest  177:    <li class=no-num><a href="#notcovered">Not in this Specification</a>
                    178: 
1.25      avankest  179:    <li class=no-num><a href="#bibref">References</a>
1.2       avankest  180: 
1.131     avankest  181:    <li class=no-num><a href="#acknowledgments">Acknowledgments</a>
1.2       avankest  182:   </ul>
                    183:   <!--end-toc-->
                    184: 
1.25      avankest  185:   <h2 id=introduction><span class=secno>1. </span>Introduction</h2>
1.2       avankest  186: 
                    187:   <p><em>This section is non-normative.</em>
                    188: 
1.60      avankest  189:   <p>The <code><a href="#xmlhttprequest-object">XMLHttpRequest</a></code>
                    190:    object implements an interface exposed by a scripting engine that allows
                    191:    scripts to perform HTTP client functionality, such as submitting form data
                    192:    or loading data from a server.
1.2       avankest  193: 
                    194:   <p>The name of the object is <code><a
1.60      avankest  195:    href="#xmlhttprequest-object">XMLHttpRequest</a></code> for compatibility
1.128     avankest  196:    with the Web, though each component of this name is potentially
1.60      avankest  197:    misleading. First, the object supports any text based format, including
                    198:    XML. Second, it can be used to make requests over both HTTP and HTTPS
                    199:    (some implementations support protocols in addition to HTTP and HTTPS, but
                    200:    that functionality is not covered by this specification). Finally, it
                    201:    supports "requests" in a broad sense of the term as it pertains to HTTP;
                    202:    namely all activity involved with HTTP requests or responses for the
                    203:    defined HTTP methods.
1.2       avankest  204: 
1.31      avankest  205:   <h3 id=examples><span class=secno>1.1. </span>Examples of Usage</h3>
1.2       avankest  206: 
                    207:   <p><em>This section is non-normative.</em>
                    208: 
1.34      avankest  209:   <p>Some [<cite><a href="#ref-ecmascript">ECMAScript</a></cite>] examples
                    210:    are listed in the specification. In addition, you can find some below.
1.2       avankest  211: 
1.25      avankest  212:   <div class=example>
1.18      avankest  213:    <p>Some simple code to do something with data from an XML document fetched
                    214:     over the network:</p>
                    215: 
1.60      avankest  216:    <pre><code>function test(data) {
1.18      avankest  217:  // taking care of data
                    218: }
                    219: 
                    220: function handler() {
1.118     avankest  221:  if(this.readyState == 4 &amp;&amp; this.status == 200) {
1.18      avankest  222:   // so far so good
1.118     avankest  223:   if(this.responseXML != null &amp;&amp; this.responseXML.getElementById('test').firstChild.data)
                    224:      // success!
1.18      avankest  225:    test(this.responseXML.getElementById('test').firstChild.data);
                    226:   else
                    227:    test(null);
1.118     avankest  228:  } else if (this.readyState == 4 &amp;&amp; this.status != 200) {
1.18      avankest  229:   // fetched the wrong page or network error...
                    230:   test(null);
                    231:  }
                    232: }
                    233: 
                    234: var client = new XMLHttpRequest();
                    235: client.onreadystatechange = handler;
                    236: client.open("GET", "test.xml");
1.60      avankest  237: client.send();</code></pre>
1.18      avankest  238: 
1.58      avankest  239:    <p>If you just want to log a message to the server:</p>
1.18      avankest  240: 
1.60      avankest  241:    <pre><code>function log(message) {
1.18      avankest  242:  var client = new XMLHttpRequest();
1.58      avankest  243:  client.open("POST", "/log");
1.59      avankest  244:  client.setRequestHeader("Content-Type", "text/plain;charset=UTF-8");
1.18      avankest  245:  client.send(message);
1.60      avankest  246: }</code></pre>
1.18      avankest  247: 
                    248:    <p>Or if you want to check the status of a document on the server:</p>
                    249: 
1.60      avankest  250:    <pre><code>function fetchStatus(address) {
1.18      avankest  251:  var client = new XMLHttpRequest();
                    252:  client.onreadystatechange = function() {
                    253:   // in case of network errors this might not give reliable results
                    254:   if(this.readyState == 4)
                    255:    returnStatus(this.status);
                    256:  }
                    257:  client.open("HEAD", address);
                    258:  client.send();
1.60      avankest  259: }</code></pre>
1.18      avankest  260:   </div>
1.2       avankest  261: 
1.31      avankest  262:   <h3 id=conformance><span class=secno>1.2. </span>Conformance</h3>
1.2       avankest  263: 
1.29      avankest  264:   <p>Everything in this specification is normative except for diagrams,
1.2       avankest  265:    examples, notes and sections marked non-normative.
                    266: 
1.25      avankest  267:   <p>The key words <em class=ct>must</em>, <em class=ct>must not</em>, <em
1.75      avankest  268:    class=ct>should</em> and <em class=ct>may</em> in this document are to be
                    269:    interpreted as described in RFC 2119. [<cite><a
                    270:    href="#RFC2119">RFC2119</a></cite>]
1.2       avankest  271: 
                    272:   <p>This specification defines the following classes of products:
                    273: 
                    274:   <dl>
1.75      avankest  275:    <dt><dfn id=conforming-user-agent>Conforming user agent</dfn>
1.2       avankest  276: 
1.75      avankest  277:    <dd>
                    278:     <p>A user agent <em class=ct>must</em> behave as described in this
1.107     avankest  279:      specification in order to be considered conformant.</p>
1.75      avankest  280: 
1.95      avankest  281:     <p>If the user agent does not support XML (including support for
                    282:      namespaces) the <a href="#xml-response-entity-body">XML response entity
                    283:      body</a> <em class=ct>must</em> (always) be <code>null</code>.</p>
                    284: 
1.76      avankest  285:     <p>User agents <em class=ct>may</em> optimize any algorithm given in this
                    286:      specification, so long as the end result is indistinguishable from the
                    287:      result that would be obtained by the specification's algorithms. (The
                    288:      algorithms in this specification are generally written with more concern
                    289:      for clarity than efficiency.)</p>
1.2       avankest  290: 
1.96      avankest  291:     <p class=note>This specification uses both the terms "conforming user
                    292:      agent(s)" and "user agent(s)" to refer to this product class.</p>
                    293: 
1.95      avankest  294:    <dt><dfn id=conforming-xml-user-agent>Conforming XML user agent</dfn>
                    295: 
                    296:    <dd>
                    297:     <p>A user agent that is a <a href="#conforming-user-agent">conforming
                    298:      user agent</a> and also supports XML (including support for namespaces).
1.2       avankest  299:   </dl>
                    300: 
1.32      avankest  301:   <h4 id=dependencies><span class=secno>1.2.1. </span>Dependencies</h4>
1.2       avankest  302: 
1.31      avankest  303:   <p>This specification relies on several underlying specifications.
1.2       avankest  304: 
1.31      avankest  305:   <dl>
                    306:    <dt>DOM
1.2       avankest  307: 
1.31      avankest  308:    <dd>
1.127     avankest  309:     <p>A <a href="#conforming-user-agent" title="conforming user
                    310:      agent">conforming user agent</a> <em class=ct>must</em> support some
1.96      avankest  311:      version of DOM Events and DOM Core, because this specification uses some
                    312:      of the features defined in those specifications. [<cite><a
                    313:      href="#DOM3EV">DOM3Events</a></cite>] [<cite><a
                    314:      href="#DOM3">DOM3Core</a></cite>]</p>
                    315: 
                    316:     <p>It <em class=ct>must</em> also support some version of the Window
                    317:      Object because some of the functionality in this specification relies on
                    318:      it. [<cite><a href="#ref-window">Window</a></cite>]</p>
1.2       avankest  319: 
1.31      avankest  320:    <dt>HTTP
1.11      avankest  321: 
1.31      avankest  322:    <dd>
1.127     avankest  323:     <p>A <a href="#conforming-user-agent" title="conforming user
                    324:      agent">conforming user agent</a> <em class=ct>must</em> support some
                    325:      version of the HTTP protocol. It <em class=ct>should</em> support any
                    326:      HTTP method that matches the <a href="#method"><code>Method</code>
                    327:      production</a> and <em class=ct>must</em> at least support the following
                    328:      methods:</p>
1.81      avankest  329: 
1.60      avankest  330:     <ul>
                    331:      <li><code>GET</code>
                    332: 
                    333:      <li><code>POST</code>
                    334: 
                    335:      <li><code>HEAD</code>
                    336: 
                    337:      <li><code>PUT</code>
                    338: 
                    339:      <li><code>DELETE</code>
                    340: 
                    341:      <li><code>OPTIONS</code>
                    342:     </ul>
                    343: 
                    344:     <p>Other requirements regarding HTTP are made throughout the
1.41      avankest  345:      specification. [<cite><a href="#RFC2616">RFC2616</a></cite>]</p>
1.43      avankest  346: 
                    347:    <dt>XML
                    348: 
                    349:    <dd>
1.96      avankest  350:     <p><a href="#conforming-xml-user-agent" title="Conforming XML user
                    351:      agent">Conforming XML user agents</a> <em class=ct>must</em> support XML
                    352:      (including support for namespaces). [<cite><a
                    353:      href="#ref-xml">XML</a></cite>] [<cite><a
                    354:      href="#ref-xmlns">XMLNS</a></cite>]
1.31      avankest  355:   </dl>
1.2       avankest  356: 
1.81      avankest  357:   <h4 id=terminology><span class=secno>1.2.2. </span>Terminology</h4>
                    358: 
                    359:   <p>There is a <dfn id=case-insensitive-match>case-insensitive match</dfn>
1.102     avankest  360:    of strings <var>s1</var> and <var>s2</var> if after uppercasing both
1.101     avankest  361:    strings (by mapping a-z to A-Z) they are identical.
1.2       avankest  362: 
1.81      avankest  363:   <h4 id=extensibility><span class=secno>1.2.3. </span>Extensibility</h4>
1.2       avankest  364: 
1.82      avankest  365:   <p>Extensions of the API defined by this specification are <em>strongly
1.31      avankest  366:    discouraged</em>. User agents, Working Groups and other interested parties
1.35      avankest  367:    should discuss extensions on a relevant public forum, preferably <a
1.31      avankest  368:    href="mailto:public-webapi@w3.org">public-webapi@w3.org</a>.
1.2       avankest  369: 
1.25      avankest  370:   <h2 id=xmlhttprequest><span class=secno>2. </span>The <code
1.16      avankest  371:    title="">XMLHttpRequest</code> Object</h2>
1.2       avankest  372: 
1.60      avankest  373:   <p>The <code><a href="#xmlhttprequest-object">XMLHttpRequest</a></code>
                    374:    object can be used by scripts to programmatically connect to their
                    375:    originating server via HTTP.
1.2       avankest  376: 
                    377:   <p>Objects implementing the <code><a
1.60      avankest  378:    href="#xmlhttprequest-object">XMLHttpRequest</a></code> interface <em
                    379:    class=ct>must</em> also implement the <code>EventTarget</code> interface.
                    380:    [<cite><a href="#DOM3EV">DOM3Events</a></cite>]
                    381: 
                    382:   <p>Objects implementing the <code title="">Window</code> interface <em
                    383:    class=ct>must</em> provide an <code title="">XMLHttpRequest()</code>
                    384:    constructor. [<cite><a href="#ref-window">Window</a></cite>]
1.2       avankest  385: 
1.25      avankest  386:   <div class=example>
1.60      avankest  387:    <p>In ECMAScript this can be used as follows:</p>
1.118     avankest  388: 
1.60      avankest  389:    <pre><code>var client = new XMLHttpRequest();</code></pre>
1.1       avankest  390:   </div>
1.2       avankest  391: 
1.60      avankest  392:   <p>When the <code title="">XMLHttpRequest()</code> constructor is invoked a
                    393:    persistent pointer to the associated <code title="">Window</code> object
                    394:    <em class=ct>must</em> be stored on the newly created object. This is the
                    395:    <dfn id=window-pointer title="Window pointer"><code>Window</code>
                    396:    pointer</dfn>. The associated <code title="">Window</code> object is the
                    397:    one of which the <code title="">XMLHttpRequest</code> constructor was
                    398:    invoked. This <a href="#window-pointer" title="Window pointer">pointer</a>
                    399:    <em class=ct>must</em> persist even if the browsing context in which the
                    400:    <code title="">Window</code> is located is destroyed (by removing it from
                    401:    a parent browsing context, for instance).
1.29      avankest  402: 
                    403:   <p>The term browsing context is defined by the <cite>Window Object
1.39      avankest  404:    1.0</cite> specification. [<cite><a href="#ref-window">Window</a></cite>]</p>
1.29      avankest  405:   <!-- XXX if the document object changes in the browsing context you get an
1.35      avankest  406:   exception in some implementations. -->
1.2       avankest  407: 
1.60      avankest  408:   <div class=example>
1.66      avankest  409:    <p>If <var><code>win</code></var> is a <code title="">Window</code> object
                    410:     <var><code>client</code></var> will have a pointer to
                    411:     <var><code>win</code></var> in the following example:</p>
1.60      avankest  412: 
1.66      avankest  413:    <pre><code>var client = new win.XMLHttpRequest()</code></pre>
1.60      avankest  414:   </div>
1.11      avankest  415: 
1.60      avankest  416:   <pre
                    417:    class=idl>interface <dfn id=xmlhttprequest-object>XMLHttpRequest</dfn> {
                    418:   // event handler
1.132     avankest  419:            attribute EventListener <a href="#onreadystatechange">onreadystatechange</a>;
1.60      avankest  420: 
                    421:   // state
1.72      avankest  422:   const unsigned short <a href="#unsent" title="UNSENT state">UNSENT</a> = 0;
1.132     avankest  423:   const unsigned short <a href="#open-state" title="OPEN state">OPEN</a> = 1;
                    424:   const unsigned short <a href="#headers-received-state" title="HEADERS_RECEIVED state">HEADERS_RECEIVED</a> = 2;
                    425:   const unsigned short <a href="#loading-state" title="LOADING state">LOADING</a> = 3;
                    426:   const unsigned short <a href="#done-state" title="DONE state">DONE</a> = 4;
                    427:   readonly attribute unsigned short <a href="#readystate">readyState</a>;
1.60      avankest  428: 
                    429:   // request
1.132     avankest  430:   void <a href="#open">open</a>(in DOMString <var>method</var>, in DOMString <var>url</var>);
                    431:   void <a href="#open">open</a>(in DOMString <var>method</var>, in DOMString <var>url</var>, in boolean <var>async</var>);
                    432:   void <a href="#open">open</a>(in DOMString <var>method</var>, in DOMString <var>url</var>, in boolean <var>async</var>, in DOMString <var>user</var>);
                    433:   void <a href="#open">open</a>(in DOMString <var>method</var>, in DOMString <var>url</var>, in boolean <var>async</var>, in DOMString <var>user</var>, in DOMString <var>password</var>);
                    434:   void <a href="#setrequestheader">setRequestHeader</a>(in DOMString <var>header</var>, in DOMString <var>value</var>);
                    435:   void <a href="#send">send</a>();
                    436:   void <a href="#send">send</a>(in DOMString <var>data</var>);
                    437:   void <a href="#send">send</a>(in Document <var>data</var>);
                    438:   void <a href="#abort">abort</a>();
1.60      avankest  439: 
                    440:   // response
1.132     avankest  441:   DOMString <a href="#getallresponseheaders">getAllResponseHeaders</a>();
                    442:   DOMString <a href="#getresponseheader">getResponseHeader</a>(in DOMString <var>header</var>);
                    443:   readonly attribute DOMString <a href="#responsetext">responseText</a>;
                    444:   readonly attribute Document <a href="#responsexml">responseXML</a>;
                    445:   readonly attribute unsigned short <a href="#status">status</a>;
                    446:   readonly attribute DOMString <a href="#statustext">statusText</a>;
1.5       avankest  447: };</pre>
1.2       avankest  448: 
1.60      avankest  449:   <p>The <code><a href="#xmlhttprequest-object">XMLHttpRequest</a></code>
1.72      avankest  450:    object can be in five states: <a href="#unsent" title="UNSENT
1.132     avankest  451:    state">UNSENT</a>, <a href="#open-state" title="OPEN state">OPEN</a>, <a
                    452:    href="#headers-received-state" title="HEADERS_RECEIVED
                    453:    state">HEADERS_RECEIVED</a>, <a href="#loading-state" title="LOADING
                    454:    state">LOADING</a> and <a href="#done-state" title="DONE state">DONE</a>.
                    455:    The current state is exposed through the <code><a
                    456:    href="#readystate">readyState</a></code> attribute. The method definitions
                    457:    below define when a state transition takes place.
1.60      avankest  458: 
                    459:   <p>When constructed, the <code><a
                    460:    href="#xmlhttprequest-object">XMLHttpRequest</a></code> object <em
1.72      avankest  461:    class=ct>must</em> be in the UNSENT state. This state is represented by
                    462:    the <dfn id=unsent title="UNSENT state"><code>UNSENT</code></dfn>
                    463:    constant, whose value is <code>0</code>.
1.60      avankest  464: 
                    465:   <p>The OPEN state is the state of the object when the <code><a
1.132     avankest  466:    href="#open">open()</a></code> method has been successfully invoked.
1.93      avankest  467:    During this state request headers can be set using <code><a
1.132     avankest  468:    href="#setrequestheader">setRequestHeader()</a></code> and the request can
                    469:    be made using <code><a href="#send">send()</a></code>. This state is
                    470:    represented by the <dfn id=open-state title="OPEN
1.60      avankest  471:    state"><code>OPEN</code></dfn> constant, whose value is <code>1</code>.
                    472: 
1.125     avankest  473:   <p>The OPEN state has an associated <dfn id=send-flag><code>send()</code>
1.105     avankest  474:    flag</dfn> which can be either "true" or "false". The initial value of the
                    475:    <code title="">send()</code> flag is "false".
1.88      avankest  476: 
1.124     avankest  477:   <p>The HEADERS_RECEIVED state is the state of the object when all response
                    478:    headers have been received. This state is represented by the <dfn
1.132     avankest  479:    id=headers-received-state title="HEADERS_RECEIVED
1.124     avankest  480:    state"><code>HEADERS_RECEIVED</code></dfn> constant, whose value is
                    481:    <code>2</code>.
                    482: 
                    483:   <p>The LOADING state is the state of the object when the response entity
1.132     avankest  484:    body is being received. This state is represented by the <dfn
                    485:    id=loading-state title="LOADING state"><code>LOADING</code></dfn>
                    486:    constant, whose value is <code>3</code>.
1.60      avankest  487: 
1.80      avankest  488:   <p>The DONE state is the state of the object when either the data transfer
                    489:    has been completed or something went wrong during the transfer (infinite
1.132     avankest  490:    redirects for instance). This state is represented by the <dfn
                    491:    id=done-state title="DONE state"><code>DONE</code></dfn> constant, whose
                    492:    value is <code>4</code>.
1.60      avankest  493: 
1.125     avankest  494:   <p>The DONE state has an associated <dfn id=error-flag>error flag</dfn>
                    495:    which can be either "true" or "false". The initial value of the error flag
                    496:    is "false".
                    497: 
1.89      avankest  498:   <p>The <dfn id=response-entity-body>response entity body</dfn> is the
1.132     avankest  499:    fragment of the <a href="#entity-body">entity body</a> received so far
1.89      avankest  500:    (LOADING state) or the complete entity body (DONE state). If there is no
                    501:    entity body the response entity body is "null".
                    502: 
                    503:   <p>The <dfn id=text-response-entity-body>text response entity body</dfn> is
1.108     avankest  504:    either a <code>DOMString</code> representing the <a
                    505:    href="#response-entity-body">response entity body</a> or
1.127     avankest  506:    <code>null</code>. The text response entity body is the return value of
                    507:    the following algorithm:
1.89      avankest  508: 
                    509:   <ol>
1.91      avankest  510:    <li>
1.108     avankest  511:     <p>If the response entity body is "null" return <code>null</code> and
                    512:      terminate these steps.</p>
1.91      avankest  513: 
                    514:    <li>
1.114     avankest  515:     <p>Let <var>charset</var> be "null".
1.112     avankest  516: 
                    517:    <li>
1.91      avankest  518:     <p>If there is no <code>Content-Type</code> header or there is a
                    519:      <code>Content-Type</code> header which contains a MIME type that is
1.117     avankest  520:      <code>text/xml</code>, <code>application/xml</code> or ends in <code
                    521:      title="">+xml</code> (ignoring any parameters) use the rules set forth
1.127     avankest  522:      in the XML specifications to determine the character encoding. Let
1.117     avankest  523:      <var>charset</var> be the determined character encoding.
1.91      avankest  524: 
                    525:    <li>
1.128     avankest  526:     <p>If there is a <code>Content-Type</code> header which contains a
1.119     avankest  527:      <code>text/html</code> MIME type follow the rules set forth in the HTML
                    528:      specification to determine the character encoding. Let
                    529:      <var>charset</var> be the determined character encoding.
                    530:    </li>
                    531:    <!-- XXX ref -->
                    532: 
                    533:    <li>
1.91      avankest  534:     <p>If the <code>Content-Type</code> MIME type contains a
1.116     avankest  535:      <code>charset</code> parameter and <var>charset</var> is "null" let
                    536:      <var>charset</var> be the value of that parameter.</p>
                    537: 
1.119     avankest  538:     <p class=note>The algorithms described by the XML and HTML specifications
                    539:      already take <code>Content-Type</code> into account.</p>
1.112     avankest  540: 
                    541:    <li> <!-- This stuff is copied from HTML5. Thanks Hixie! -->
1.114     avankest  542:     <p>If <var>charset</var> is "null" then, for each of the rows in the
                    543:      following table, starting with the first one and going down, if the
1.128     avankest  544:      first bytes of <var>bytes</var> match the bytes given in the first
                    545:      column, then let <var>charset</var> be the encoding given in the cell in
                    546:      the second column of that row. If there is no match <var>charset</var>
                    547:      remains "null".</p>
1.112     avankest  548: 
                    549:     <table>
                    550:      <thead>
                    551:       <tr>
                    552:        <th>Bytes in Hexadecimal
                    553: 
                    554:        <th>Description
                    555: 
                    556:      <tbody>
                    557:       <tr>
                    558:        <td>00 00 FE FF
                    559: 
                    560:        <td>UTF-32BE BOM
                    561: 
                    562:       <tr>
                    563:        <td>FF FE 00 00
                    564: 
                    565:        <td>UTF-32LE BOM
                    566: 
                    567:       <tr>
                    568:        <td>FE FF
                    569: 
                    570:        <td>UTF-16BE BOM
                    571: 
                    572:       <tr>
                    573:        <td>FF FE
                    574: 
                    575:        <td>UTF-16LE BOM
                    576: 
                    577:       <tr>
                    578:        <td>EF BB BF
                    579: 
1.118     avankest  580:        <td>UTF-8 BOM<!-- nobody uses this
                    581:       <tr>
                    582:        <td>DD 73 66 73
                    583:        <td>UTF-EBCDIC
1.112     avankest  584: -->
                    585:         
                    586:     </table>
                    587: 
                    588:    <li>
1.114     avankest  589:     <p>If <var>charset</var> is "null" let <var>charset</var> be UTF-8.
1.91      avankest  590: 
                    591:    <li>
1.108     avankest  592:     <p>Return the result of decoding the response entity body using
1.97      avankest  593:      <var>charset</var>. Or, if that fails, return <code>null</code>.
1.89      avankest  594:   </ol>
                    595: 
1.108     avankest  596:   <p>The <dfn id=xml-response-entity-body>XML response entity body</dfn> is
                    597:    either a <code>Document</code> representing the <a
1.127     avankest  598:    href="#response-entity-body">response entity body</a> or
                    599:    <code>null</code>. The XML response entity body is the return value of the
                    600:    following algorithm:
1.89      avankest  601: 
                    602:   <ol>
1.91      avankest  603:    <li>
1.108     avankest  604:     <p>If the response entity body is "null" terminate these steps and return
                    605:      <code>null</code>.
1.89      avankest  606: 
                    607:    <li>
1.104     avankest  608:     <p>If a <code>Content-Type</code> is present and it does not contain a
                    609:      MIME type (ignoring any parameters) that is <code>text/xml</code>,
1.117     avankest  610:      <code>application/xml</code> or ends in <code title="">+xml</code>
                    611:      terminate these steps and return <code>null</code>. (Do not terminate
                    612:      these steps if there is no <code>Content-Type</code> header at all.)
1.89      avankest  613: 
                    614:    <li>
1.129     avankest  615:     <p>Parse the response entity body into a document tree following the
                    616:      rules from the XML specifications. Let the result be <var>parsed
                    617:      document</var>. If this fails (unsupported character encoding, namespace
                    618:      well-formedness error et cetera) terminate these steps return
                    619:      <code>null</code>. [<cite><a href="#ref-xml">XML</a></cite>] [<cite><a
                    620:      href="#ref-xmlns">XMLNS</a></cite>]</p>
                    621: 
                    622:     <p class=note>Scripts in the resulting document tree will not be
                    623:      executed, resources referenced will not be loaded and no associated XSLT
                    624:      will be applied.</p>
1.89      avankest  625: 
                    626:    <li>
1.97      avankest  627:     <p>Return an object implementing the <code>Document</code> interface
                    628:      representing the <var>parsed document</var>.
1.89      avankest  629:   </ol>
                    630: 
1.6       avankest  631:   <dl>
1.132     avankest  632:    <dt><dfn id=onreadystatechange><code>onreadystatechange</code></dfn> of
                    633:     type <code>EventListener</code>
1.2       avankest  634: 
                    635:    <dd>
                    636:     <p>An attribute that takes an <code>EventListener</code> as value that
1.60      avankest  637:      <em class=ct>must</em> be invoked along with any other appropriate event
                    638:      listeners that are registered on this object when a <code><a
1.132     avankest  639:      href="#readystatechange">readystatechange</a></code> event is dispatched
                    640:      on it during the bubbling phase. Its initial value <em
1.88      avankest  641:      class=ct>must</em> be <code>null</code>.</p>
1.2       avankest  642: 
1.132     avankest  643:    <dt><dfn id=readystate><code>readyState</code></dfn> of type
1.2       avankest  644:     <code>unsigned short</code>, readonly
                    645: 
                    646:    <dd>
1.60      avankest  647:     <p>The attribute <em class=ct>must</em> be the value of the constant
                    648:      corresponding to the object's current state.</p>
1.2       avankest  649: 
1.132     avankest  650:    <dt><dfn id=open title=open><code>open(<var>method</var>, <var>url</var>,
                    651:     <var>async</var>, <var>user</var>, <var>password</var>)</code></dfn>,
                    652:     method
1.2       avankest  653: 
1.60      avankest  654:    <dd>
                    655:     <p>When invoked, the user agent <em class=ct>must</em> follow the
1.97      avankest  656:      following steps (unless otherwise indicated):</p>
1.2       avankest  657: 
1.60      avankest  658:     <ol>
                    659:      <li>
1.98      avankest  660:       <p>If the <var>method</var> argument does not match the <dfn
1.60      avankest  661:        id=method><code>Method</code> production</dfn> defined in section
1.99      avankest  662:        5.1.1 of RFC 2616 raise a <code>SYNTAX_ERR</code> exception and
                    663:        terminate these steps. [<cite><a href="#RFC2616">RFC2616</a></cite>]
1.2       avankest  664: 
1.60      avankest  665:      <li>
                    666:       <p>If the given <var>method</var> is not supported for security reasons
                    667:        the user agent <em class=ct>should</em> raise a
1.99      avankest  668:        <code>SECURITY_ERR</code> exception and terminate these steps.
1.2       avankest  669: 
1.60      avankest  670:      <li>
                    671:       <p>Let <var>stored method</var> be <var>method</var>.
1.2       avankest  672: 
1.60      avankest  673:      <li>
1.81      avankest  674:       <p>If <var>method</var> <a href="#case-insensitive-match"
                    675:        title="case-insensitive match">case-insensitively matches</a>
                    676:        <code>GET</code>, <code>POST</code>, <code>HEAD</code>,
1.97      avankest  677:        <code>PUT</code>, <code>DELETE</code> or <code>OPTIONS</code> convert
                    678:        it to its uppercase equivalent (by mapping a-z to A-Z) and let
                    679:        <var>stored method</var> be the result.
1.69      avankest  680:      </li>
                    681:      <!-- WebKit (and supposedly Firefox) also uppercase: CONNECT, COPY,
                    682:      INDEX, LOCK, M-POST, MKCOL, MOVE, PROPFIND, PROPPATCH, TRACE and UNLOCK.
                    683:      Not sure if TRACE and CONNECT are worth it though. They raise a
                    684:      SECURITY_ERR exception anyway... -->
1.2       avankest  685: 
1.60      avankest  686:      <li>
                    687:       <p>Drop the fragment identifier (if any) from <var>url</var> and let
                    688:        <var>stored url</var> be the result of that operation.
1.2       avankest  689: 
1.60      avankest  690:      <li>
1.97      avankest  691:       <p>If <var>stored url</var> is a relative reference resolve it using
                    692:        the current value of the <code>baseURI</code> attribute of the
                    693:        <code>Document</code> object currently associated with the <a
1.60      avankest  694:        href="#window-pointer"><code>Window</code> pointer</a>. If this fails
1.99      avankest  695:        raise a <code>SYNTAX_ERR</code> exception and terminate these steps.
1.2       avankest  696: 
1.60      avankest  697:      <li>
1.102     avankest  698:       <p>If <var>stored url</var> contains an unsupported scheme raise a
                    699:        <code>NOT_SUPPORTED_ERR</code> and terminate these steps.
                    700: 
                    701:      <li>
1.60      avankest  702:       <p>If the <code>"user:password"</code> format in the
                    703:        <code>userinfo</code> production defined in section 3.2.1 of RFC 3986
                    704:        is not supported for the relevant scheme and <var>stored url</var>
1.99      avankest  705:        contains this format raise a <code>SYNTAX_ERR</code> and terminate
                    706:        these steps. [<cite><a href="#ref-rfc3986">RFC3986</a></cite>]
1.2       avankest  707: 
1.60      avankest  708:      <li>
                    709:       <p>If <var>stored url</var> contains the <code>"user:password"</code>
                    710:        format let <var>stored user</var> be the user part and <var>stored
                    711:        password</var> be the password part.
1.2       avankest  712: 
1.60      avankest  713:      <li>
                    714:       <p>If <var>stored url</var> just contains the <code>"user"</code>
                    715:        format let <var>stored user</var> be the user part.
1.24      avankest  716: 
1.60      avankest  717:      <li>
                    718:       <p>If <var>stored url</var> is non same-origin the user agent <em
                    719:        class=ct>should</em> raise a <code>SECURITY_ERR</code> exception and
1.99      avankest  720:        terminate these steps.</p>
1.70      avankest  721: 
                    722:       <p class=note>This specification does not define what constitutes as
1.118     avankest  723:        non same-origin. It is expected that what constitutes as non
1.103     avankest  724:        same-origin will be defined before this specification eventually
                    725:        reaches the W3C Recommendation status by way of referencing a
                    726:        specification that defines it.<!-- XXX reference HTML5? --></p>
1.60      avankest  727: 
                    728:      <li>
                    729:       <p>Let <var>async</var> be the value of the <var>async</var> argument
1.103     avankest  730:        or <code>true</code> if it was omitted.
1.60      avankest  731: 
                    732:      <li>
1.127     avankest  733:       <p>If the <var>user</var> argument was not omitted, and its syntax does
                    734:        not match that specified by the relevant authentication scheme, raise
                    735:        a <code>SYNTAX_ERR</code> exception and terminate these steps.
1.60      avankest  736: 
                    737:      <li>
                    738:       <p>If the <var>user</var> argument was not omitted and is not
                    739:        <code>null</code> let <var>stored user</var> be <var>user</var>
                    740:        encoded using the encoding specified in the relevant authentication
                    741:        scheme or UTF-8 if the scheme fails to specify an encoding.</p>
1.2       avankest  742: 
1.60      avankest  743:       <p class=note>This step overrides any user that may have been set by
                    744:        the <var>url</var> argument.</p>
1.17      avankest  745: 
1.60      avankest  746:      <li>
                    747:       <p>If the <var>user</var> argument was not omitted and is
                    748:        <code>null</code> remove <var>stored user</var>.
1.17      avankest  749: 
1.60      avankest  750:      <li>
                    751:       <p>If the <var>password</var> argument was not omitted and its syntax
                    752:        does not match that specified by the relevant authentication scheme
1.99      avankest  753:        raise a <code>SYNTAX_ERR</code> exception and terminate these steps.
1.17      avankest  754: 
1.60      avankest  755:      <li>
                    756:       <p>If the <var>password</var> argument was not omitted and is not
                    757:        <code>null</code> let <var>stored password</var> be
                    758:        <var>password</var> encoded using the encoding specified in the
                    759:        relevant authentication scheme or UTF-8 if the scheme fails to specify
                    760:        an encoding.
1.17      avankest  761: 
1.60      avankest  762:      <li>
                    763:       <p>If the <var>password</var> argument was not omitted and is
                    764:        <code>null</code> remove <var>stored password</var>.
1.17      avankest  765: 
1.60      avankest  766:      <li>
1.109     avankest  767:       <p><a href="#abort-send-algorithm" title="abort send()">Abort the
                    768:        <code>send()</code> algorithm</a>, set <a
                    769:        href="#response-entity-body">response entity body</a> to "null" and
                    770:        reset the list of request headers.
1.17      avankest  771: 
1.60      avankest  772:       <p>
1.44      avankest  773: 
1.60      avankest  774:      <li>
1.109     avankest  775:       <p>The user agent <em class=ct>should</em> cancel any network activity
                    776:        for which the object is responsible.
1.60      avankest  777:      </li>
                    778:      <!-- we can hardly require it... -->
1.22      avankest  779: 
1.60      avankest  780:      <li>
1.132     avankest  781:       <p>Switch the object to the <a href="#open-state" title="OPEN
                    782:        state">OPEN</a> state, set the <a
                    783:        href="#send-flag"><code>send()</code> flag</a> to "false" and then
                    784:        synchronously dispatch a <code><a
                    785:        href="#readystatechange">readystatechange</a></code> event on the
1.97      avankest  786:        object and return the method call.
1.60      avankest  787:     </ol>
1.24      avankest  788: 
1.25      avankest  789:     <p class=note>A future version or extension of this specification will
1.35      avankest  790:      most likely define a way of doing cross-site requests.</p>
1.26      avankest  791: 
1.132     avankest  792:    <dt><dfn id=setrequestheader
1.25      avankest  793:     title=setrequestheader><code>setRequestHeader(<var>header</var>,
1.18      avankest  794:     <var>value</var>)</code></dfn>, method
1.6       avankest  795: 
                    796:    <dd>
1.47      avankest  797:     <p>Each request has a list of request headers with associated values.
                    798:      This method can be used to manipulate those values and set new request
                    799:      headers.</p>
                    800: 
1.60      avankest  801:     <p>When invoked, the user agent <em class=ct>must</em> follow the
1.97      avankest  802:      following steps (unless otherwise indicated):</p>
1.60      avankest  803: 
                    804:     <ol>
                    805:      <li>
1.132     avankest  806:       <p>If the state of the object is not <a href="#open-state" title="OPEN
1.97      avankest  807:        state">OPEN</a> raise an <code>INVALID_STATE_ERR</code> exception and
1.99      avankest  808:        terminate these steps.
1.6       avankest  809: 
1.60      avankest  810:      <li>
1.104     avankest  811:       <p>If the <a href="#send-flag"><code>send()</code> flag</a> is "true"
1.99      avankest  812:        raise an <code>INVALID_STATE_ERR</code> exception and terminate these
1.97      avankest  813:        steps.
1.60      avankest  814: 
                    815:      <li>
1.98      avankest  816:       <p>If the <var>header</var> argument does not match the <dfn
1.60      avankest  817:        id=field-name><code>field-name</code> production</dfn> as defined by
1.97      avankest  818:        section 4.2 of RFC 2616 or is <code>null</code> raise a
1.99      avankest  819:        <code>SYNTAX_ERR</code> exception and terminate these steps. [<cite><a
1.97      avankest  820:        href="#RFC2616">RFC2616</a></cite>]
1.71      avankest  821: 
                    822:      <li>
1.99      avankest  823:       <p>If the <var>value</var> argument is <code>null</code> terminate
                    824:        these steps. (Do not raise an exception.)
1.71      avankest  825:      </li>
                    826:      <!-- undefined is to be treated as null here... -->
1.60      avankest  827: 
                    828:      <li>
1.98      avankest  829:       <p>If the <var>value</var> argument does not match the <dfn
1.60      avankest  830:        id=field-value><code>field-value</code> production</dfn> as defined by
1.99      avankest  831:        section 4.2 of RFC 2616 raise a <code>SYNTAX_ERR</code> and terminate
1.97      avankest  832:        these steps. [<cite><a href="#RFC2616">RFC2616</a></cite>]
1.60      avankest  833: 
                    834:      <li>
1.133     avankest  835:       <p>For security reasons, these steps <em class=ct>should</em> be
1.99      avankest  836:        terminated if the <var>header</var> argument <a
                    837:        href="#case-insensitive-match" title="case-insensitive
                    838:        match">case-insensitively matches</a> one of the following headers:</p>
1.34      avankest  839: 
                    840:       <ul>
                    841:        <li><code>Accept-Charset</code>
                    842: 
                    843:        <li><code>Accept-Encoding</code>
                    844: 
1.69      avankest  845:        <li><code>Connection</code>
                    846: 
1.34      avankest  847:        <li><code>Content-Length</code>
                    848: 
1.69      avankest  849:        <li><code>Content-Transfer-Encoding</code>
                    850: 
                    851:        <li><code>Date</code>
                    852: 
1.34      avankest  853:        <li><code>Expect</code>
                    854: 
                    855:        <li><code>Host</code>
                    856: 
                    857:        <li><code>Keep-Alive</code>
                    858: 
                    859:        <li><code>Referer</code>
                    860: 
                    861:        <li><code>TE</code>
                    862: 
                    863:        <li><code>Trailer</code>
                    864: 
                    865:        <li><code>Transfer-Encoding</code>
                    866: 
                    867:        <li><code>Upgrade</code>
1.69      avankest  868: 
                    869:        <li><code>Via</code>
1.34      avankest  870:       </ul>
1.6       avankest  871: 
1.60      avankest  872:      <li>
1.133     avankest  873:       <p>Also for security reasons, these steps <em class=ct>should</em> be
                    874:        terminated if the first six characters of the <var>header</var>
                    875:        argument <a href="#case-insensitive-match" title="case-insensitive
                    876:        match">case-insensitively match</a> <code>Proxy-</code>.
                    877: 
                    878:      <li>
1.60      avankest  879:       <p>If the <var>header</var> argument is not in the list of request
1.97      avankest  880:        headers append the <var>header</var> with its associated
1.99      avankest  881:        <var>value</var> to the list and terminate these steps.
1.46      avankest  882: 
1.60      avankest  883:      <li>
                    884:       <p>If the <var>header</var> argument is in the list of request headers
1.97      avankest  885:        either use multiple headers, combine the values or use a combination
                    886:        of those (section 4.2, RFC 2616). [<cite><a
                    887:        href="#RFC2616">RFC2616</a></cite>]
                    888:      </li>
                    889:      <!-- XXX it seems UAs always combine the values -->
1.60      avankest  890:     </ol>
1.18      avankest  891: 
1.132     avankest  892:     <p class=note>See also the <code><a href="#send">send()</a></code> method
                    893:      regarding user agent header handling for caching, authentication,
1.47      avankest  894:      proxies, and cookies.</p>
                    895: 
1.25      avankest  896:     <div class=example>
1.60      avankest  897:      <pre><code>// The following script:
1.18      avankest  898: var client = new XMLHttpRequest();
                    899: client.open('GET', 'demo.cgi');
                    900: client.setRequestHeader('X-Test', 'one');
                    901: client.setRequestHeader('X-Test', 'two');
                    902: client.send();
                    903: 
                    904: // ...would result in the following header being sent:
                    905: ...
                    906: X-Test: one, two
1.60      avankest  907: ...</code></pre>
1.18      avankest  908:     </div>
1.6       avankest  909: 
1.132     avankest  910:    <dt><dfn id=send title=send><code>send(<var>data</var>)</code></dfn>,
1.25      avankest  911:     method
1.2       avankest  912: 
                    913:    <dd>
1.132     avankest  914:     <p>The <code><a href="#send">send()</a></code> method initiates the
1.107     avankest  915:      request and its optional argument provides the <a
1.132     avankest  916:      href="#entity-body">entity body</a>. Authors are strongly encouraged to
                    917:      ensure that they have specified the <code>Content-Type</code> header via
                    918:      <code><a href="#setrequestheader">setRequestHeader()</a></code> before
                    919:      invoking <code><a href="#send">send()</a></code> with a
1.107     avankest  920:      non-<code>null</code> <var>data</var> argument.</p>
1.60      avankest  921: 
                    922:     <p>When invoked, the user agent <em class=ct>must</em> follow the
1.109     avankest  923:      following steps (unless otherwise noted). Note that this algorithm might
1.132     avankest  924:      get aborted if the <code><a href="#open">open()</a></code> or <code><a
                    925:      href="#abort">abort()</a></code> method is invoked. When the <dfn
                    926:      id=abort-send-algorithm title="abort send()"><code>send()</code>
                    927:      algorithm is aborted</dfn> the user agent <em class=ct>must</em>
                    928:      terminate the algorithm after finishing the step it is on.</p>
1.109     avankest  929: 
                    930:     <p class=note>The following algorithm can not be aborted through script
                    931:      when <var>async</var> is <code>false</code>. It can only be aborted when
                    932:      <var>async</var> is <code>true</code> and only after the method call has
                    933:      returned.</p>
1.60      avankest  934: 
                    935:     <ol>
                    936:      <li>
1.132     avankest  937:       <p>If the state of the object is not <a href="#open-state" title="OPEN
1.97      avankest  938:        state">OPEN</a> raise an <code>INVALID_STATE_ERR</code> exception and
1.99      avankest  939:        terminate these steps.
1.60      avankest  940: 
                    941:      <li>
1.104     avankest  942:       <p>If the <a href="#send-flag"><code>send()</code> flag</a> is "true"
1.99      avankest  943:        raise an <code>INVALID_STATE_ERR</code> exception and terminate these
1.97      avankest  944:        steps.
1.60      avankest  945: 
                    946:      <li>
1.104     avankest  947:       <p>If <var>async</var> is <code>true</code> set the <a
                    948:        href="#send-flag"><code>send()</code> flag</a> to "true".
1.103     avankest  949: 
                    950:      <li>
1.60      avankest  951:       <p>If the <var>data</var> argument has not been omitted and is not
1.132     avankest  952:        <code>null</code> use it for the <dfn id=entity-body>entity body</dfn>
                    953:        as defined by section 7.2 of RFC 2616 observing the following rules:
                    954:        [<cite><a href="#RFC2616">RFC2616</a></cite>]</p>
1.60      avankest  955: 
1.120     avankest  956:       <dl class=switch>
1.60      avankest  957:        <dt><var>data</var> is a <code>DOMString</code>
                    958: 
1.79      avankest  959:        <dd>
1.97      avankest  960:         <p>Encode <var>data</var> using UTF-8 for transmission.
1.60      avankest  961: 
                    962:        <dt><var>data</var> is a <code>Document</code>
                    963: 
                    964:        <dd>
1.97      avankest  965:         <p>Serialize <var>data</var> into a namespace well-formed XML
                    966:          document and encoded using the encoding given by
                    967:          <code><var>data</var>.xmlEncoding</code>, if specified, or UTF-8
                    968:          otherwise. Or, if this fails because the <code>Document</code>
                    969:          cannot be serialized act as if <var>data</var> is <code>null</code>.</p>
                    970: 
                    971:         <p>If no <code>Content-Type</code> header is in the list of request
1.127     avankest  972:          headers append a <code>Content-Type</code> header to the list of
                    973:          request headers with a value of <code>application/xml</code>.</p>
1.60      avankest  974: 
                    975:         <p class=note>Subsequent changes to the <code>Document</code> have no
                    976:          effect on what is submitted.</p>
                    977: 
                    978:        <dt><var>data</var> is not a <code>DOMString</code> or
                    979:         <code>Document</code>
                    980: 
1.79      avankest  981:        <dd>
1.97      avankest  982:         <p>Use the stringification mechanisms of the host language on
                    983:          <var>data</var> and treat the result as if <var>data</var> is a
                    984:          <code>DOMString</code>. Or, if this fails, act as if <var>data</var>
                    985:          is <code>null</code>.
1.60      avankest  986:       </dl>
                    987: 
1.127     avankest  988:       <p>If the <var>data</var> argument has been omitted, or is
                    989:        <code>null</code>, no entity body is used in the request.</p>
1.60      avankest  990: 
                    991:      <li>
1.72      avankest  992:       <p>Make a request to <var>stored url</var>, using HTTP method
                    993:        <var>stored method</var>, user <var>stored user</var> (if provided)
                    994:        and password <var>stored password</var> (if provided), taking into
                    995:        account the entity body, list of request headers and the rules listed
                    996:        directly after this set of steps.
1.60      avankest  997: 
                    998:      <li>
1.97      avankest  999:       <p>Synchronously dispatch a <code><a
1.132     avankest 1000:        href="#readystatechange">readystatechange</a></code> event on the
1.97      avankest 1001:        object.</p>
                   1002: 
                   1003:       <p class=note>The state of the object does not change. The event is
                   1004:        dispatched for historical reasons.</p>
1.68      avankest 1005: 
                   1006:      <li>
1.103     avankest 1007:       <p>If <var>async</var> is <code>true</code> return the <code><a
1.132     avankest 1008:        href="#send">send()</a></code> method call. (Do not terminate the
1.103     avankest 1009:        steps in the algorithm though.)
1.60      avankest 1010: 
                   1011:      <li>
1.124     avankest 1012:       <p>While downloading the resource the following rules are to be
                   1013:        observed.</p>
1.119     avankest 1014: 
1.120     avankest 1015:       <dl class=switch>
1.119     avankest 1016:        <dt>If the response is an HTTP redirect
                   1017: 
                   1018:        <dd>
                   1019:         <p>If the redirect does not violate security or infinite loop
                   1020:          precautions and the scheme is supported transparently follow it and
                   1021:          go to the start of this step.</p>
                   1022: 
                   1023:         <p class=note>HTTP places requirements on the user agent regarding
                   1024:          the preservation of the request method and entity body during
                   1025:          redirects, and also requires users to be notified of certain kinds
                   1026:          of automatic redirections.</p>
                   1027:         <!-- Arguably HTTP should be fixed for the latter case. No browser
                   1028:         follows that as far as I know. -->
                   1029:         
                   1030:         <p>Otherwise, follow the following set of steps:</p>
                   1031: 
                   1032:         <ol>
                   1033:          <li>
1.125     avankest 1034:           <p>Set the <a href="#response-entity-body">response entity body</a>
                   1035:            to "null", the <a href="#error-flag">error flag</a> to "true" and
                   1036:            reset the list of request headers.
1.119     avankest 1037: 
                   1038:          <li>
1.132     avankest 1039:           <p>Synchronously switch the state to <a href="#done-state"
                   1040:            title="DONE state">DONE</a>.
1.119     avankest 1041: 
                   1042:          <li>
                   1043:           <p>If <var>async</var> is set to <code>false</code> raise a
                   1044:            <code><a href="#network-err">NETWORK_ERR</a></code> exception and
                   1045:            terminate the overall algorithm.
                   1046: 
                   1047:          <li>
                   1048:           <p>Synchronously dispatch a <code><a
1.132     avankest 1049:            href="#readystatechange">readystatechange</a></code> event on the
                   1050:            object.
1.119     avankest 1051: 
                   1052:          <li>
                   1053:           <p>Terminate the overall algorithm.
                   1054:         </ol>
                   1055: 
                   1056:         <p class=note>It is likely that a future version of the <code><a
                   1057:          href="#xmlhttprequest-object">XMLHttpRequest</a></code> object will
                   1058:          dispatch an <code>error</code> event here as well.</p>
                   1059: 
                   1060:        <dt>If the user cancels the download
                   1061: 
                   1062:        <dd>
                   1063:         <p>Run the following set of steps:</p>
                   1064: 
                   1065:         <ol>
                   1066:          <li>
1.125     avankest 1067:           <p>Set the <a href="#response-entity-body">response entity body</a>
                   1068:            to "null", the <a href="#error-flag">error flag</a> to "true" and
                   1069:            reset the list of request headers.
1.119     avankest 1070: 
                   1071:          <li>
1.132     avankest 1072:           <p>Synchronously switch the state to <a href="#done-state"
                   1073:            title="DONE state">DONE</a>.
1.119     avankest 1074: 
                   1075:          <li>
1.122     avankest 1076:           <p>If <var>async</var> is set to <code>false</code> raise an
                   1077:            <code><a href="#abort-err">ABORT_ERR</a></code> exception and
1.119     avankest 1078:            terminate the overall algorithm.
                   1079: 
                   1080:          <li>
                   1081:           <p>Synchronously dispatch a <code><a
1.132     avankest 1082:            href="#readystatechange">readystatechange</a></code> event on the
                   1083:            object.
1.119     avankest 1084: 
                   1085:          <li>
                   1086:           <p>Terminate the overall algorithm.
                   1087:         </ol>
                   1088: 
                   1089:         <p class=note>It is likely that a future version of the <code><a
                   1090:          href="#xmlhttprequest-object">XMLHttpRequest</a></code> object will
1.122     avankest 1091:          dispatch an <code title="">abort</code> event here as well.</p>
1.119     avankest 1092: 
                   1093:        <dt>In case of network errors
1.118     avankest 1094: 
1.119     avankest 1095:        <dd>
1.127     avankest 1096:         <p>In case of DNS errors, or other type of network errors, run the
                   1097:          following set of steps. <span class=note>This does not include HTTP
                   1098:          responses that indicate some type of error, such as HTTP status code
1.119     avankest 1099:          410.</span></p>
                   1100: 
                   1101:         <ol>
                   1102:          <li>
1.125     avankest 1103:           <p>Set the <a href="#response-entity-body">response entity body</a>
                   1104:            to "null", the <a href="#error-flag">error flag</a> to "true" and
                   1105:            reset the list of request headers.
1.119     avankest 1106: 
                   1107:          <li>
1.132     avankest 1108:           <p>Synchronously switch the state to <a href="#done-state"
                   1109:            title="DONE state">DONE</a>.
1.119     avankest 1110: 
                   1111:          <li>
                   1112:           <p>If <var>async</var> is set to <code>false</code> raise a
                   1113:            <code><a href="#network-err">NETWORK_ERR</a></code> exception and
                   1114:            terminate the overall algorithm.
                   1115: 
                   1116:          <li>
                   1117:           <p>Synchronously dispatch a <code><a
1.132     avankest 1118:            href="#readystatechange">readystatechange</a></code> event on the
                   1119:            object.
1.119     avankest 1120: 
                   1121:          <li>
                   1122:           <p>Terminate the overall algorithm.
                   1123:         </ol>
                   1124: 
                   1125:         <p class=note>It is likely that a future version of the <code><a
                   1126:          href="#xmlhttprequest-object">XMLHttpRequest</a></code> object will
                   1127:          dispatch an <code>error</code> event here as well.</p>
                   1128: 
                   1129:        <dt>Once all HTTP headers have been received
1.60      avankest 1130: 
1.119     avankest 1131:        <dd>
                   1132:         <p>If all HTTP headers have been received, before receiving the
1.124     avankest 1133:          message body (if any), run the following steps:</p>
1.60      avankest 1134: 
1.119     avankest 1135:         <ol>
                   1136:          <li>
1.132     avankest 1137:           <p>Synchronously switch the state to <a
                   1138:            href="#headers-received-state" title="HEADERS_RECEIVED
                   1139:            state">HEADERS_RECEIVED</a>.
1.119     avankest 1140: 
                   1141:          <li>
                   1142:           <p>Synchronously dispatch a <code><a
1.132     avankest 1143:            href="#readystatechange">readystatechange</a></code> event on the
                   1144:            object.
1.124     avankest 1145:         </ol>
                   1146: 
                   1147:        <dt>Once the first byte (or more) of the response entity body has been
                   1148:         received
                   1149: 
                   1150:        <dt>If there is no response entity body
1.119     avankest 1151: 
1.124     avankest 1152:        <dd>
                   1153:         <p>Once the first byte of the response entity body has been received
                   1154:          or in case there is no response entity body, run the following
                   1155:          steps:</p>
                   1156: 
                   1157:         <ol>
1.119     avankest 1158:          <li>
1.132     avankest 1159:           <p>Synchronously switch the state to <a href="#loading-state"
1.119     avankest 1160:            title="LOADING state">LOADING</a>.
                   1161: 
                   1162:          <li>
                   1163:           <p>Synchronously dispatch a <code><a
1.132     avankest 1164:            href="#readystatechange">readystatechange</a></code> event on the
                   1165:            object.
1.119     avankest 1166:         </ol>
                   1167:       </dl>
1.60      avankest 1168: 
1.125     avankest 1169:       <p>Finally, once the complete resource has been downloaded go to the
                   1170:        next step.</p>
1.60      avankest 1171: 
                   1172:      <li>
1.83      avankest 1173:       <p>When the request has successfully completed loading, synchronously
1.132     avankest 1174:        switch the state to <a href="#done-state" title="DONE state">DONE</a>
                   1175:        and then synchronously dispatch a <code><a
                   1176:        href="#readystatechange">readystatechange</a></code> event on the
1.97      avankest 1177:        object and return the method call in case of <var>async</var> being
                   1178:        <code>false</code>.
1.60      avankest 1179:     </ol>
1.19      avankest 1180: 
1.92      avankest 1181:     <p>If the user agent allows the user to configure a proxy it <em
1.25      avankest 1182:      class=ct>should</em> modify the request appropriately; <abbr title="in
1.2       avankest 1183:      other words">i.e.</abbr>, connect to the proxy host instead of the
                   1184:      origin server, modify the <code>Request-Line</code> and send
                   1185:      <code>Proxy-Authorization</code> headers as specified.</p>
                   1186: 
1.44      avankest 1187:     <p>If the user agent supports HTTP Authentication it <em
                   1188:      class=ct>should</em> consider requests originating from this object to
                   1189:      be part of the protection space that includes the accessed URIs and send
1.19      avankest 1190:      <code>Authorization</code> headers and handle <code>401
1.73      avankest 1191:      Unauthorised</code> requests appropriately. If authentication fails,
1.44      avankest 1192:      user agents <em class=ct>should</em> prompt the users for credentials.
                   1193:      [<cite><a href="#ref-rfc2617">RFC2617</a></cite>]</p>
1.19      avankest 1194: 
1.59      avankest 1195:     <p>If the user agent supports HTTP State Management it <em
1.44      avankest 1196:      class=ct>should</em> persist, discard and send cookies (as received in
                   1197:      the <code>Set-Cookie</code> and <code>Set-Cookie2</code> response
                   1198:      headers, and sent in the <code>Cookie</code> header) as applicable.
1.51      avankest 1199:      [<cite><a href="#ref-rfc2965">RFC2965</a></cite>]</p>
1.44      avankest 1200: 
                   1201:     <p>If the user agent implements a HTTP cache it <em class=ct>should</em>
                   1202:      respect <code>Cache-Control</code> request headers set by the script
                   1203:      (<abbr title="for example">e.g.</abbr>, <code>Cache-Control:
                   1204:      no-cache</code> bypasses the cache). It <em class=ct>must not</em> send
1.25      avankest 1205:      <code>Cache-Control</code> or <code>Pragma</code> request headers
1.44      avankest 1206:      automatically unless the user explicitly requests such behaviour
                   1207:      (<abbr>e.g.</abbr>, by (force-)reloading the page). <code>304 Not
                   1208:      Modified</code> responses that are a result of a user agent generated
                   1209:      conditional request <em class=ct>must</em> be presented as <code>200
1.59      avankest 1210:      OK</code> responses with the appropriate content. The user agent <em
1.44      avankest 1211:      class=ct>must</em> allow scripts to override automatic cache validation
                   1212:      by setting request headers (e.g., <code>If-None-Match</code>,
1.16      avankest 1213:      <code>If-Modified-Since</code>), in which case <code>304 Not
1.44      avankest 1214:      Modified</code> responses <em class=ct>must</em> be passed through.
                   1215:      [<cite><a href="#RFC2616">RFC2616</a></cite>]</p>
1.2       avankest 1216: 
1.44      avankest 1217:     <p>If the user agent implements server-driven content-negotiation it <em
1.25      avankest 1218:      class=ct>should</em> set <code>Accept-Language</code>,
1.18      avankest 1219:      <code>Accept-Encoding</code> and <code>Accept-Charset</code> headers as
1.25      avankest 1220:      appropriate; it <em class=ct>must not</em> automatically set the
1.18      avankest 1221:      <code>Accept</code> header. Responses to such requests <em
1.128     avankest 1222:      class=ct>must</em> have the content-encodings automatically decoded.
1.44      avankest 1223:      [<cite><a href="#RFC2616">RFC2616</a></cite>]</p>
1.18      avankest 1224: 
1.132     avankest 1225:    <dt><dfn id=abort><code>abort()</code></dfn>, method
1.6       avankest 1226: 
                   1227:    <dd>
1.62      avankest 1228:     <p>When invoked, the user agent <em class=ct>must</em> run the following
1.97      avankest 1229:      steps (unless otherwise noted):</p>
1.6       avankest 1230: 
1.62      avankest 1231:     <ol>
                   1232:      <li>
1.109     avankest 1233:       <p><a href="#abort-send-algorithm" title="abort send()">Abort the
                   1234:        <code>send()</code> algorithm</a>, set the <a
1.125     avankest 1235:        href="#response-entity-body">response entity body</a> to "null", the
                   1236:        <a href="#send-flag"><code>send()</code> flag</a> to "false", the <a
                   1237:        href="#error-flag">error flag</a> to "true" and remove any registered
                   1238:        request headers.
1.62      avankest 1239: 
                   1240:      <li>
1.109     avankest 1241:       <p>The user agent <em class=ct>should</em> cancel any network activity
                   1242:        for which the object is responsible.
1.62      avankest 1243: 
1.80      avankest 1244:      <li>
1.86      avankest 1245:       <p>If the state is <a href="#unsent" title="UNSENT state">UNSENT</a>,
1.132     avankest 1246:        <a href="#open-state" title="OPEN state">OPEN</a> and the <a
1.104     avankest 1247:        href="#send-flag"><code>send()</code> flag</a> is "false", or <a
1.132     avankest 1248:        href="#done-state" title="DONE state">DONE</a> go to the next step.</p>
1.84      avankest 1249: 
1.132     avankest 1250:       <p>Otherwise, switch the state to <a href="#done-state" title="DONE
1.97      avankest 1251:        state">DONE</a> and synchronously dispatch a <code><a
1.132     avankest 1252:        href="#readystatechange">readystatechange</a></code> event on the
1.84      avankest 1253:        object.</p>
1.68      avankest 1254: 
1.62      avankest 1255:      <li>
1.72      avankest 1256:       <p>Switch the state to <a href="#unsent" title="UNSENT
1.98      avankest 1257:        state">UNSENT</a>. (Do not dispatch the <code><a
1.132     avankest 1258:        href="#readystatechange">readystatechange</a></code> event.)</p>
1.62      avankest 1259: 
1.83      avankest 1260:       <p class=note>It is likely that a future version of the <code><a
                   1261:        href="#xmlhttprequest-object">XMLHttpRequest</a></code> object will
                   1262:        dispatch an <code title="">abort</code> event here as well.</p>
1.62      avankest 1263:     </ol>
1.26      avankest 1264: 
1.6       avankest 1265:    <dt><dfn
1.132     avankest 1266:     id=getallresponseheaders><code>getAllResponseHeaders()</code></dfn>,
1.13      avankest 1267:     method
1.2       avankest 1268: 
                   1269:    <dd>
1.62      avankest 1270:     <p>When invoked, the user agent <em class=ct>must</em> run the following
                   1271:      steps:</p>
1.60      avankest 1272: 
                   1273:     <ol>
1.77      avankest 1274:      <li>
1.125     avankest 1275:       <p>If the state is <a href="#unsent" title="UNSENT state">UNSENT</a> or
1.132     avankest 1276:        <a href="#open-state" title="OPEN state">OPEN</a> raise an
1.125     avankest 1277:        <code>INVALID_STATE_ERR</code> exception and terminate these steps.
                   1278: 
                   1279:      <li>
                   1280:       <p>If the <a href="#error-flag">error flag</a> is "true" return
                   1281:        <code>null</code> and terminate these steps.
1.77      avankest 1282: 
                   1283:      <li>
1.97      avankest 1284:       <p>Return all the HTTP headers, as a single string, with each header
                   1285:        line separated by a U+000D CR U+000A LF pair excluding the status
                   1286:        line.
1.60      avankest 1287:     </ol>
1.6       avankest 1288: 
1.25      avankest 1289:     <div class=example>
1.60      avankest 1290:      <pre><code>// The following script:
1.6       avankest 1291: var client = new XMLHttpRequest();
1.18      avankest 1292: client.open("GET", "test.txt", true);
1.6       avankest 1293: client.send();
1.16      avankest 1294: client.onreadystatechange = function() {
1.17      avankest 1295:  if(this.readyState == 3) {
1.16      avankest 1296:   print(this.getAllResponseHeaders());
                   1297:  }
                   1298: }
1.6       avankest 1299: 
                   1300: // ...should output something similar to the following text:
                   1301: Date: Sun, 24 Oct 2004 04:58:38 GMT
                   1302: Server: Apache/1.3.31 (Unix)
                   1303: Keep-Alive: timeout=15, max=99
                   1304: Connection: Keep-Alive
                   1305: Transfer-Encoding: chunked
1.60      avankest 1306: Content-Type: text/plain; charset=utf-8</code></pre>
1.6       avankest 1307:     </div>
                   1308: 
1.132     avankest 1309:    <dt><dfn id=getresponseheader
1.25      avankest 1310:     title=getresponseheader><code>getResponseHeader(<var>header</var>)</code></dfn>,
1.13      avankest 1311:     method
1.2       avankest 1312: 
1.6       avankest 1313:    <dd>
1.60      avankest 1314:     <p>When the method is invoked, the user agent <em class=ct>must</em> run
                   1315:      the following steps:</p>
                   1316: 
                   1317:     <ol>
1.77      avankest 1318:      <li>
1.125     avankest 1319:       <p>If the state is <a href="#unsent" title="UNSENT state">UNSENT</a> or
1.132     avankest 1320:        <a href="#open-state" title="OPEN state">OPEN</a> raise an
1.125     avankest 1321:        <code>INVALID_STATE_ERR</code> exception and terminate these steps.
                   1322: 
                   1323:      <li>
                   1324:       <p>If the <a href="#error-flag">error flag</a> is "true" return
                   1325:        <code>null</code> and terminate these steps.
1.17      avankest 1326: 
1.77      avankest 1327:      <li>
1.98      avankest 1328:       <p>If the <var>header</var> argument does not match the <a
1.97      avankest 1329:        href="#field-name"><code>field-name</code> production</a> raise a
1.99      avankest 1330:        <code>SYNTAX_ERR</code> exception and terminate these steps.
1.77      avankest 1331: 
                   1332:      <li>
1.81      avankest 1333:       <p>If the <var>header</var> argument <a href="#case-insensitive-match"
                   1334:        title="case-insensitive match">case-insensitively matches</a> multiple
1.128     avankest 1335:        HTTP headers for the last request sent, return the values of these
1.97      avankest 1336:        headers as a single concatenated string separated from each other by
1.99      avankest 1337:        an U+002C COMMA followed by an U+0020 SPACE and terminate these steps.
1.77      avankest 1338: 
                   1339:      <li>
1.81      avankest 1340:       <p>If the <var>header</var> argument <a href="#case-insensitive-match"
                   1341:        title="case-insensitive match">case-insensitively matches</a> a single
1.97      avankest 1342:        HTTP header for the last request sent return the value of that header
1.99      avankest 1343:        and terminate these steps.
1.77      avankest 1344: 
                   1345:      <li>
1.97      avankest 1346:       <p>Return <code>null</code>.
1.60      avankest 1347:     </ol>
1.17      avankest 1348: 
1.25      avankest 1349:     <div class=example>
1.60      avankest 1350:      <pre><code>// The following script:
1.1       avankest 1351: var client = new XMLHttpRequest();
1.18      avankest 1352: client.open("GET", "test.txt", true);
1.6       avankest 1353: client.send();
1.16      avankest 1354: client.onreadystatechange = function() {
1.17      avankest 1355:  if(this.readyState == 3) {
1.18      avankest 1356:   print(client.getResponseHeader("Content-Type"));
1.16      avankest 1357:  }
                   1358: }
1.1       avankest 1359: 
1.6       avankest 1360: // ...should output something similar to the following text:
1.60      avankest 1361: Content-Type: text/plain; charset=utf-8</code></pre>
1.2       avankest 1362:     </div>
                   1363: 
1.132     avankest 1364:    <dt><dfn id=responsetext><code>responseText</code></dfn> of type
1.9       avankest 1365:     <code>DOMString</code>, readonly
1.6       avankest 1366: 
                   1367:    <dd>
1.89      avankest 1368:     <p>On getting, the user agent <em class=ct>must</em> run the following
                   1369:      steps:</p>
                   1370: 
                   1371:     <ol>
                   1372:      <li>
1.132     avankest 1373:       <p>If the state is not <a href="#loading-state" title="LOADING
                   1374:        state">LOADING</a> or <a href="#done-state" title="DONE
                   1375:        state">DONE</a> raise an <code>INVALID_STATE_ERR</code> exception and
                   1376:        terminate these steps.
1.6       avankest 1377: 
1.89      avankest 1378:      <li>
                   1379:       <p>Return the <a href="#text-response-entity-body">text response entity
                   1380:        body</a>.
                   1381:     </ol>
1.12      avankest 1382: 
1.132     avankest 1383:    <dt><dfn id=responsexml><code>responseXML</code></dfn> of type
1.9       avankest 1384:     <code>Document</code>, readonly
1.6       avankest 1385: 
                   1386:    <dd>
1.76      avankest 1387:     <p>On getting, the user agent <em class=ct>must</em> run the following
                   1388:      steps:</p>
                   1389: 
                   1390:     <ol>
                   1391:      <li>
1.132     avankest 1392:       <p>If the state is not <a href="#done-state" title="DONE
                   1393:        state">DONE</a> raise an <code>INVALID_STATE_ERR</code> exception and
                   1394:        terminate these steps.
1.76      avankest 1395: 
                   1396:      <li>
1.89      avankest 1397:       <p>Return the <a href="#xml-response-entity-body">XML response entity
                   1398:        body</a>.
1.76      avankest 1399:     </ol>
1.12      avankest 1400: 
1.132     avankest 1401:    <dt><dfn id=status><code>status</code></dfn> of type <code>unsigned
1.9       avankest 1402:     short</code>, readonly
1.6       avankest 1403: 
                   1404:    <dd>
1.73      avankest 1405:     <p>On getting, if available, it <em class=ct>must</em> return the HTTP
                   1406:      status code sent by the server (typically <code>200</code> for a
                   1407:      successful request). Otherwise, if not available, the user agent <em
                   1408:      class=ct>must</em> raise an <code>INVALID_STATE_ERR</code> exception.</p>
1.12      avankest 1409: 
1.132     avankest 1410:    <dt><dfn id=statustext><code>statusText</code></dfn> of type
1.9       avankest 1411:     <code>DOMString</code>, readonly
1.2       avankest 1412: 
1.6       avankest 1413:    <dd>
1.73      avankest 1414:     <p>On getting, if available, it <em class=ct>must</em> return the HTTP
                   1415:      status text sent by the server (appears after the status code).
                   1416:      Otherwise, if not available, the user agent <em class=ct>must</em> raise
                   1417:      an <code>INVALID_STATE_ERR</code> exception.</p>
1.2       avankest 1418:   </dl>
                   1419: 
1.60      avankest 1420:   <h3 id=events><span class=secno>2.1. </span>Events for the <code
1.33      avankest 1421:    title="">XMLHttpRequest</code> Object</h3>
1.2       avankest 1422: 
1.1       avankest 1423:   <p>These sections describe the various events that can be dispatched on the
1.2       avankest 1424:    object implementing the <code><a
1.60      avankest 1425:    href="#xmlhttprequest-object">XMLHttpRequest</a></code> interface. For
                   1426:    this version of the specification only one event is defined.
1.2       avankest 1427: 
1.1       avankest 1428:   <dl>
1.132     avankest 1429:    <dt><dfn id=readystatechange><code>readystatechange</code></dfn>
1.2       avankest 1430: 
1.73      avankest 1431:    <dd>When the user agent dispatches a <code
                   1432:     title="">readystatechange</code> event (as indicated above) it <em
                   1433:     class=ct>must not</em> bubble, <em class=ct>must not</em> be cancelable
                   1434:     and <em class=ct>must</em> implement the <code>Event</code> interface.
                   1435:     Its <code>namespaceURI</code> attribute <em class=ct>must</em> be
                   1436:     <code>null</code>. [<cite><a href="#DOM3EV">DOM3Events</a></cite>]
1.1       avankest 1437:   </dl>
1.2       avankest 1438: 
1.60      avankest 1439:   <h3 id=exceptions><span class=secno>2.2. </span>Exceptions for the <code
1.33      avankest 1440:    title="">XMLHttpRequest</code> Object</h3>
                   1441: 
1.34      avankest 1442:   <pre
1.118     avankest 1443:    class=idl>exception <dfn id=xmlhttprequestexception>XMLHttpRequestException</dfn> {
1.33      avankest 1444:   unsigned short     code;
1.118     avankest 1445: };
1.122     avankest 1446: const unsigned short <a href="#network-err">NETWORK_ERR</a> = 101;
                   1447: const unsigned short <a href="#abort-err">ABORT_ERR</a> = 102;</pre>
1.33      avankest 1448: 
1.35      avankest 1449:   <p>The <dfn id=network-err><code>NETWORK_ERR</code></dfn> exception is
1.122     avankest 1450:    thrown when a network error occurs in synchronous requests.
                   1451: 
                   1452:   <p>The <dfn id=abort-err><code>ABORT_ERR</code></dfn> exception is thrown
                   1453:    when the user aborts a request in synchronous requests.
                   1454: 
1.132     avankest 1455:   <p>See the section on <code><a href="#send">send()</a></code> for more
1.122     avankest 1456:    details.
1.33      avankest 1457: 
1.31      avankest 1458:   <h2 class=no-num id=notcovered>Not in this Specification</h2>
                   1459: 
                   1460:   <p><em>This section is non normative.</em>
                   1461: 
1.73      avankest 1462:   <p>This specification does not include the following features which are
                   1463:    being considered for a future version of this specification:
1.31      avankest 1464: 
                   1465:   <ul>
                   1466:    <li><code>load</code> event and <code>onload</code> attribute;
                   1467: 
                   1468:    <li><code>error</code> event and <code>onerror</code> attribute;
                   1469: 
                   1470:    <li><code>progress</code> event and <code>onprogress</code> attribute;
                   1471: 
                   1472:    <li><code title="">abort</code> event and <code>onabort</code> attribute;
                   1473: 
                   1474:    <li>Timers have been suggested, perhaps an <code>ontimeout</code>
                   1475:     attribute;
                   1476: 
                   1477:    <li>Property to disable following redirects;
                   1478: 
1.32      avankest 1479:    <li><code title="">responseXML</code> for <code>text/html</code>
                   1480:     documents;
1.31      avankest 1481: 
1.42      avankest 1482:    <li>Cross-site <code title="">XMLHttpRequest</code>;
                   1483: 
1.88      avankest 1484:    <li><code>responseBody</code> to deal with byte streams;
1.42      avankest 1485: 
1.115     avankest 1486:    <li><code>overrideMimeType</code> to fix up MIME types;
                   1487: 
1.88      avankest 1488:    <li><code>getRequestHeader()</code> and
                   1489:     <code>removeRequestHeader()</code>.
1.31      avankest 1490:   </ul>
                   1491: 
1.25      avankest 1492:   <h2 class=no-num id=bibref>References</h2>
1.2       avankest 1493: 
1.7       avankest 1494:   <dl>
1.39      avankest 1495:    <dt>[<dfn id=DOM3>DOM3Core</dfn>]
1.2       avankest 1496: 
1.15      avankest 1497:    <dd><cite><a href="http://www.w3.org/TR/DOM-Level-3-Core">Document Object
                   1498:     Model (DOM) Level 3 Core Specification</a></cite>, A. Le Hors, P. Le
                   1499:     Hégaret, L. Wood, G. Nicol, J. Robie, M. Champion, S. Byrne, editors.
1.118     avankest 1500:     W3C, April 2004.
1.2       avankest 1501: 
1.39      avankest 1502:    <dt>[<dfn id=DOM3EV>DOM3Events</dfn>]
1.2       avankest 1503: 
                   1504:    <dd><cite><a href="http://www.w3.org/TR/DOM-Level-3-Events/">Document
1.15      avankest 1505:     Object Model (DOM) Level 3 Events Specification</a></cite>, Björn
1.118     avankest 1506:     Höhrmann, editor. W3C, April 2006.
1.15      avankest 1507: 
1.39      avankest 1508:    <dt>[<dfn id=ref-ecmascript>ECMAScript</dfn>]
1.18      avankest 1509: 
                   1510:    <dd><cite><a
                   1511:     href="http://www.ecma-international.org/publications/standards/Ecma-262.htm">ECMAScript
                   1512:     Language Specification</a></cite>, Third Edition. ECMA, December 1999.
                   1513: 
1.39      avankest 1514:    <dt>[<dfn id=ref-rfc2046>RFC2046</dfn>]
1.18      avankest 1515: 
1.22      avankest 1516:    <dd><cite><a href="http://ietf.org/rfc/rfc2046">Multipurpose Internet Mail
                   1517:     Extensions (MIME) Part Two: Media Types</a></cite>, N. Freed, N.
                   1518:     Borenstein, editors. IETF, November 1996.
1.18      avankest 1519: 
1.39      avankest 1520:    <dt>[<dfn id=RFC2119>RFC2119</dfn>]
1.15      avankest 1521: 
1.118     avankest 1522:    <dd><cite><a href="http://ietf.org/rfc/rfc2119">Key words for use in RFCs
                   1523:     to Indicate Requirement Levels</a></cite>, S. Bradner. IETF, March 1997.
1.15      avankest 1524: 
1.39      avankest 1525:    <dt>[<dfn id=RFC2616>RFC2616</dfn>]
1.15      avankest 1526: 
                   1527:    <dd><cite><a href="http://ietf.org/rfc/rfc2616">Hypertext Transfer
                   1528:     Protocol -- HTTP/1.1</a></cite>, R. Fielding, J. Gettys, J. Mogul, H.
1.93      avankest 1529:     Frystyk, L. Masinter, P. Leach, T. Berners-Lee, editors. IETF, June 1999.
1.15      avankest 1530: 
1.39      avankest 1531:    <dt>[<dfn id=ref-rfc2617>RFC2617</dfn>]
1.15      avankest 1532: 
                   1533:    <dd><cite><a href="http://ietf.org/rfc/rfc2617">HTTP Authentication: Basic
1.93      avankest 1534:     and Digest Access Authentication</a></cite>, P. Hallam-Baker, J.
                   1535:     Hostetler, S. Lawrence, P. Leach, A. Luotonen, L. Stewart, editors. IETF,
                   1536:     June 1999.
1.2       avankest 1537: 
1.39      avankest 1538:    <dt>[<dfn id=ref-rfc2965>RFC2965</dfn>]
1.2       avankest 1539: 
1.22      avankest 1540:    <dd><cite><a href="http://ietf.org/rfc/rfc2965">HTTP State Management
                   1541:     Mechanism</a></cite>, D. Kristol, L. Montulli, editors. IETF, October
                   1542:     2000.
                   1543: 
1.39      avankest 1544:    <dt>[<dfn id=ref-rfc3986>RFC3986</dfn>]
1.2       avankest 1545: 
1.15      avankest 1546:    <dd><cite><a href="http://ietf.org/rfc/rfc3986">Uniform Resource
                   1547:     Identifier (URI): Generic Syntax</a></cite>, T. Berners-Lee, R. Fielding,
                   1548:     L. Masinter, editors. IETF, January 2005.
1.30      avankest 1549: 
1.39      avankest 1550:    <dt>[<dfn id=ref-window>Window</dfn>]
1.30      avankest 1551: 
                   1552:    <dd><cite><a href="http://www.w3.org/TR/Window/">Window Object
                   1553:     1.0</a></cite>, I. Davis, M. Stachowiak, editors. W3C, April 2006.
1.43      avankest 1554: 
                   1555:    <dt>[<dfn id=ref-xml>XML</dfn>]
                   1556: 
                   1557:    <dd><cite><a href="http://www.w3.org/TR/xml/">Extensible Markup Language
                   1558:     (XML) 1.0 (Fourth Edition)</a></cite>, T. Bray, J. Paoli, C.
1.118     avankest 1559:     Sperberg-McQueen, E. Maler, F. Yergeau, editors. W3C, September 2006.
1.43      avankest 1560: 
                   1561:    <dt>[<dfn id=ref-xmlns>XMLNS</dfn>]
                   1562: 
                   1563:    <dd><cite><a href="http://www.w3.org/TR/xml-names/">Namespaces in XML
1.118     avankest 1564:     (Second Edition)</a></cite>, T. Bray, D. Hollander, A. Layman, R. Tobin,
                   1565:     editors. W3C, August 2006.
1.2       avankest 1566:   </dl>
                   1567: 
1.131     avankest 1568:   <h2 class=no-num id=acknowledgments>Acknowledgments</h2>
1.2       avankest 1569: 
                   1570:   <p><em>This section is non-normative</em>
                   1571: 
1.9       avankest 1572:   <p>The editor would like to thank to the following people who have
1.35      avankest 1573:    contributed to this specification (ordered by first name):
1.2       avankest 1574: 
1.1       avankest 1575:   <ul>
1.113     avankest 1576:    <li>Ahmed Kamel
                   1577: 
1.25      avankest 1578:    <li>Alex Hopmann
                   1579: 
1.9       avankest 1580:    <li>Alex Vincent
                   1581: 
1.19      avankest 1582:    <li>Alexey Proskuryakov
                   1583: 
1.2       avankest 1584:    <li>Asbjørn Ulsberg
                   1585: 
                   1586:    <li>Boris Zbarsky
                   1587: 
                   1588:    <li>Björn Höhrmann
                   1589: 
                   1590:    <li>Cameron McCormack
                   1591: 
                   1592:    <li>Christophe Jolif
                   1593: 
                   1594:    <li>Charles McCathieNevile
                   1595: 
1.56      avankest 1596:    <li>Dan Winship
                   1597: 
1.73      avankest 1598:    <li>David Håsäther
                   1599: 
1.2       avankest 1600:    <li>Dean Jackson
                   1601: 
1.127     avankest 1602:    <li>Denis Sureau
                   1603: 
1.2       avankest 1604:    <li>Doug Schepers
                   1605: 
                   1606:    <li>Douglas Livingstone
                   1607: 
1.131     avankest 1608:    <li>Elliotte Harold
                   1609: 
1.113     avankest 1610:    <li>Eric Lawrence
                   1611: 
                   1612:    <li>Gideon Cohn
                   1613: 
1.2       avankest 1614:    <li>Gorm Haug Eriksen
                   1615: 
                   1616:    <li>Hallvord R. M. Steen
                   1617: 
                   1618:    <li>Håkon Wium Lie
                   1619: 
                   1620:    <li>Ian Davis
                   1621: 
                   1622:    <li>Ian Hickson
                   1623: 
                   1624:    <li>Ivan Herman
                   1625: 
                   1626:    <li>Jens Lindström
                   1627: 
                   1628:    <li>Jim Deegan
                   1629: 
                   1630:    <li>Jim Ley
                   1631: 
1.113     avankest 1632:    <li>Joe Farro
                   1633: 
1.2       avankest 1634:    <li>Jonas Sicking
                   1635: 
                   1636:    <li>Julian Reschke
                   1637: 
                   1638:    <li>Karl Dubost
                   1639: 
                   1640:    <li>Maciej Stachowiak
                   1641: 
1.9       avankest 1642:    <li>Magnus Kristiansen
                   1643: 
1.2       avankest 1644:    <li>Marc Hadley
                   1645: 
1.55      avankest 1646:    <li>Marcos Caceres
                   1647: 
1.88      avankest 1648:    <li>Mark Baker
                   1649: 
1.2       avankest 1650:    <li>Mark Nottingham
                   1651: 
1.93      avankest 1652:    <li>Mohamed Zergaoui
                   1653: 
1.2       avankest 1654:    <li>Pawel Glowacki
                   1655: 
                   1656:    <li>Robin Berjon
                   1657: 
                   1658:    <li>Ruud Steltenpool
1.35      avankest 1659: 
                   1660:    <li>Simon Pieters
1.113     avankest 1661: 
1.126     avankest 1662:    <li>Stewart Brodie
                   1663: 
1.113     avankest 1664:    <li>Sunava Dutta
                   1665: 
                   1666:    <li>Zhenbin Xu
1.1       avankest 1667:   </ul>
1.2       avankest 1668: 
                   1669:   <p>Special thanks to the Microsoft employees who first implemented the
1.60      avankest 1670:    <code><a href="#xmlhttprequest-object">XMLHttpRequest</a></code>
                   1671:    interface, which was first widely deployed by the Windows Internet
                   1672:    Explorer browser.
1.2       avankest 1673: 
1.56      avankest 1674:   <p>Special thanks also to the WHATWG for drafting an initial version of
1.131     avankest 1675:    this specification in their Web Applications 1.0 document (now renamed to
                   1676:    HTML&nbsp;5).
1.2       avankest 1677: 
                   1678:   <p>Thanks also to all those who have helped to improve this specification
                   1679:    by sending suggestions and corrections. (Please, keep bugging us with your
                   1680:    issues!)

Webmaster