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

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

Webmaster