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

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.115   ! avankest   33:     draft<!--W3C Working Draft--> 23 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.115   ! avankest   39:      href="http://www.w3.org/TR/2007/WD-XMLHttpRequest-20070523/">http://www.w3.org/TR/2007/WD-XMLHttpRequest-20070523/</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.115   ! avankest  102:   <p>This is the 23 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>
1.114     avankest  503:     <p>Let <var>charset</var> be "null".
1.112     avankest  504: 
                    505:    <li>
1.91      avankest  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
1.114     avankest  511:      determine the character encoding. Let <var>charset</var> be the
1.92      avankest  512:      determined character encoding.
1.91      avankest  513: 
                    514:    <li>
                    515:     <p>If the <code>Content-Type</code> MIME type contains a
1.114     avankest  516:      <code>charset</code> parameter let <var>charset</var> be the value of
                    517:      that parameter.
1.112     avankest  518: 
                    519:    <li> <!-- This stuff is copied from HTML5. Thanks Hixie! -->
1.114     avankest  520:     <p>If <var>charset</var> is "null" then, for each of the rows in the
                    521:      following table, starting with the first one and going down, if the
                    522:      start of the entity body (<var>bytes</var>) is equal to or greater than
                    523:      the number of bytes in the first column, and the first bytes of
                    524:      <var>bytes</var> match the bytes given in the first column, then let
                    525:      <var>charset</var> be the encoding given in the cell in the second
                    526:      column of that row. When an encoding is determined or when no encoding
                    527:      is determined go to the next step:</p>
1.112     avankest  528: 
                    529:     <table>
                    530:      <thead>
                    531:       <tr>
                    532:        <th>Bytes in Hexadecimal
                    533: 
                    534:        <th>Description
                    535: 
                    536:      <tbody>
                    537:       <tr>
                    538:        <td>00 00 FE FF
                    539: 
                    540:        <td>UTF-32BE BOM
                    541: 
                    542:       <tr>
                    543:        <td>FF FE 00 00
                    544: 
                    545:        <td>UTF-32LE BOM
                    546: 
                    547:       <tr>
                    548:        <td>FE FF
                    549: 
                    550:        <td>UTF-16BE BOM
                    551: 
                    552:       <tr>
                    553:        <td>FF FE
                    554: 
                    555:        <td>UTF-16LE BOM
                    556: 
                    557:       <tr>
                    558:        <td>EF BB BF
                    559: 
                    560:        <td>UTF-8 BOM<!-- nobody uses this
                    561:       <tr>
                    562:        <td>DD 73 66 73
                    563:        <td>UTF-EBCDIC
                    564: -->
                    565:         
                    566:     </table>
                    567: 
                    568:    <li>
1.114     avankest  569:     <p>If <var>charset</var> is "null" let <var>charset</var> be UTF-8.
1.91      avankest  570: 
                    571:    <li>
1.108     avankest  572:     <p>Return the result of decoding the response entity body using
1.97      avankest  573:      <var>charset</var>. Or, if that fails, return <code>null</code>.
1.89      avankest  574:   </ol>
                    575: 
1.108     avankest  576:   <p>The <dfn id=xml-response-entity-body>XML response entity body</dfn> is
                    577:    either a <code>Document</code> representing the <a
                    578:    href="#response-entity-body">response entity body</a> or <code>null</code>
                    579:    and is determined by running the following algorithm (the return value is
                    580:    its value):
1.89      avankest  581: 
                    582:   <ol>
1.91      avankest  583:    <li>
1.108     avankest  584:     <p>If the response entity body is "null" terminate these steps and return
                    585:      <code>null</code>.
1.89      avankest  586: 
                    587:    <li>
1.104     avankest  588:     <p>If a <code>Content-Type</code> is present and it does not contain a
                    589:      MIME type (ignoring any parameters) that is <code>text/xml</code>,
1.92      avankest  590:      <code>application/xml</code>, <code>text/xsl</code> or ends in <code
1.97      avankest  591:      title="">+xml</code> terminate these steps and return <code>null</code>.
1.100     avankest  592:      (Do not terminate these steps if there is no <code>Content-Type</code>
                    593:      header at all.)
1.89      avankest  594: 
                    595:    <li>
1.108     avankest  596:     <p>Parse the response entity body following the rules from the XML
                    597:      specifications. Let the result be <var>parsed document</var>. If this
                    598:      fails (unsupported character encoding, namespace well-formedness error
                    599:      et cetera) terminate these steps return <code>null</code>. [<cite><a
1.97      avankest  600:      href="#ref-xml">XML</a></cite>] [<cite><a
1.89      avankest  601:      href="#ref-xmlns">XMLNS</a></cite>]
                    602: 
                    603:    <li>
1.97      avankest  604:     <p>Return an object implementing the <code>Document</code> interface
                    605:      representing the <var>parsed document</var>.
1.89      avankest  606:   </ol>
                    607: 
1.6       avankest  608:   <dl>
1.25      avankest  609:    <dt><dfn id=dfn-onreadystatechange><code>onreadystatechange</code></dfn>
1.2       avankest  610:     of type <code>EventListener</code>
                    611: 
                    612:    <dd>
                    613:     <p>An attribute that takes an <code>EventListener</code> as value that
1.60      avankest  614:      <em class=ct>must</em> be invoked along with any other appropriate event
                    615:      listeners that are registered on this object when a <code><a
                    616:      href="#dfn-readystatechange">readystatechange</a></code> event is
1.88      avankest  617:      dispatched on it during the bubbling phase. Its initial value <em
                    618:      class=ct>must</em> be <code>null</code>.</p>
1.2       avankest  619: 
1.25      avankest  620:    <dt><dfn id=dfn-readystate><code>readyState</code></dfn> of type
1.2       avankest  621:     <code>unsigned short</code>, readonly
                    622: 
                    623:    <dd>
1.60      avankest  624:     <p>The attribute <em class=ct>must</em> be the value of the constant
                    625:      corresponding to the object's current state.</p>
1.2       avankest  626: 
1.60      avankest  627:    <dt><dfn id=dfn-open title=open><code>open(<var>method</var>,
                    628:     <var>url</var>, <var>async</var>, <var>user</var>,
                    629:     <var>password</var>)</code></dfn>, method
1.2       avankest  630: 
1.60      avankest  631:    <dd>
                    632:     <p>When invoked, the user agent <em class=ct>must</em> follow the
1.97      avankest  633:      following steps (unless otherwise indicated):</p>
1.2       avankest  634: 
1.60      avankest  635:     <ol>
                    636:      <li>
1.98      avankest  637:       <p>If the <var>method</var> argument does not match the <dfn
1.60      avankest  638:        id=method><code>Method</code> production</dfn> defined in section
1.99      avankest  639:        5.1.1 of RFC 2616 raise a <code>SYNTAX_ERR</code> exception and
                    640:        terminate these steps. [<cite><a href="#RFC2616">RFC2616</a></cite>]
1.2       avankest  641: 
1.60      avankest  642:      <li>
                    643:       <p>If the given <var>method</var> is not supported for security reasons
                    644:        the user agent <em class=ct>should</em> raise a
1.99      avankest  645:        <code>SECURITY_ERR</code> exception and terminate these steps.
1.2       avankest  646: 
1.60      avankest  647:      <li>
                    648:       <p>Let <var>stored method</var> be <var>method</var>.
1.2       avankest  649: 
1.60      avankest  650:      <li>
1.81      avankest  651:       <p>If <var>method</var> <a href="#case-insensitive-match"
                    652:        title="case-insensitive match">case-insensitively matches</a>
                    653:        <code>GET</code>, <code>POST</code>, <code>HEAD</code>,
1.97      avankest  654:        <code>PUT</code>, <code>DELETE</code> or <code>OPTIONS</code> convert
                    655:        it to its uppercase equivalent (by mapping a-z to A-Z) and let
                    656:        <var>stored method</var> be the result.
1.69      avankest  657:      </li>
                    658:      <!-- WebKit (and supposedly Firefox) also uppercase: CONNECT, COPY,
                    659:      INDEX, LOCK, M-POST, MKCOL, MOVE, PROPFIND, PROPPATCH, TRACE and UNLOCK.
                    660:      Not sure if TRACE and CONNECT are worth it though. They raise a
                    661:      SECURITY_ERR exception anyway... -->
1.2       avankest  662: 
1.60      avankest  663:      <li>
                    664:       <p>Drop the fragment identifier (if any) from <var>url</var> and let
                    665:        <var>stored url</var> be the result of that operation.
1.2       avankest  666: 
1.60      avankest  667:      <li>
1.97      avankest  668:       <p>If <var>stored url</var> is a relative reference resolve it using
                    669:        the current value of the <code>baseURI</code> attribute of the
                    670:        <code>Document</code> object currently associated with the <a
1.60      avankest  671:        href="#window-pointer"><code>Window</code> pointer</a>. If this fails
1.99      avankest  672:        raise a <code>SYNTAX_ERR</code> exception and terminate these steps.
1.2       avankest  673: 
1.60      avankest  674:      <li>
1.102     avankest  675:       <p>If <var>stored url</var> contains an unsupported scheme raise a
                    676:        <code>NOT_SUPPORTED_ERR</code> and terminate these steps.
                    677: 
                    678:      <li>
1.60      avankest  679:       <p>If the <code>"user:password"</code> format in the
                    680:        <code>userinfo</code> production defined in section 3.2.1 of RFC 3986
                    681:        is not supported for the relevant scheme and <var>stored url</var>
1.99      avankest  682:        contains this format raise a <code>SYNTAX_ERR</code> and terminate
                    683:        these steps. [<cite><a href="#ref-rfc3986">RFC3986</a></cite>]
1.2       avankest  684: 
1.60      avankest  685:      <li>
                    686:       <p>If <var>stored url</var> contains the <code>"user:password"</code>
                    687:        format let <var>stored user</var> be the user part and <var>stored
                    688:        password</var> be the password part.
1.2       avankest  689: 
1.60      avankest  690:      <li>
                    691:       <p>If <var>stored url</var> just contains the <code>"user"</code>
                    692:        format let <var>stored user</var> be the user part.
1.24      avankest  693: 
1.60      avankest  694:      <li>
                    695:       <p>If <var>stored url</var> is non same-origin the user agent <em
                    696:        class=ct>should</em> raise a <code>SECURITY_ERR</code> exception and
1.99      avankest  697:        terminate these steps.</p>
1.70      avankest  698: 
                    699:       <p class=note>This specification does not define what constitutes as
1.103     avankest  700:        non same-origin. It is expected that what constiutes as non
                    701:        same-origin will be defined before this specification eventually
                    702:        reaches the W3C Recommendation status by way of referencing a
                    703:        specification that defines it.<!-- XXX reference HTML5? --></p>
1.60      avankest  704: 
                    705:      <li>
                    706:       <p>Let <var>async</var> be the value of the <var>async</var> argument
1.103     avankest  707:        or <code>true</code> if it was omitted.
1.60      avankest  708: 
                    709:      <li>
                    710:       <p>If the <var>user</var> argument was not omitted and its syntax does
1.97      avankest  711:        not match that specified by the relevant authentication scheme raise a
1.99      avankest  712:        <code>SYNTAX_ERR</code> exception and terminate these steps.
1.60      avankest  713: 
                    714:      <li>
                    715:       <p>If the <var>user</var> argument was not omitted and is not
                    716:        <code>null</code> let <var>stored user</var> be <var>user</var>
                    717:        encoded using the encoding specified in the relevant authentication
                    718:        scheme or UTF-8 if the scheme fails to specify an encoding.</p>
1.2       avankest  719: 
1.60      avankest  720:       <p class=note>This step overrides any user that may have been set by
                    721:        the <var>url</var> argument.</p>
1.17      avankest  722: 
1.60      avankest  723:      <li>
                    724:       <p>If the <var>user</var> argument was not omitted and is
                    725:        <code>null</code> remove <var>stored user</var>.
1.17      avankest  726: 
1.60      avankest  727:      <li>
                    728:       <p>If the <var>password</var> argument was not omitted and its syntax
                    729:        does not match that specified by the relevant authentication scheme
1.99      avankest  730:        raise a <code>SYNTAX_ERR</code> exception and terminate these steps.
1.17      avankest  731: 
1.60      avankest  732:      <li>
                    733:       <p>If the <var>password</var> argument was not omitted and is not
                    734:        <code>null</code> let <var>stored password</var> be
                    735:        <var>password</var> encoded using the encoding specified in the
                    736:        relevant authentication scheme or UTF-8 if the scheme fails to specify
                    737:        an encoding.
1.17      avankest  738: 
1.60      avankest  739:      <li>
                    740:       <p>If the <var>password</var> argument was not omitted and is
                    741:        <code>null</code> remove <var>stored password</var>.
1.17      avankest  742: 
1.60      avankest  743:      <li>
1.109     avankest  744:       <p><a href="#abort-send-algorithm" title="abort send()">Abort the
                    745:        <code>send()</code> algorithm</a>, set <a
                    746:        href="#response-entity-body">response entity body</a> to "null" and
                    747:        reset the list of request headers.
1.17      avankest  748: 
1.60      avankest  749:       <p>
1.44      avankest  750: 
1.60      avankest  751:      <li>
1.109     avankest  752:       <p>The user agent <em class=ct>should</em> cancel any network activity
                    753:        for which the object is responsible.
1.60      avankest  754:      </li>
                    755:      <!-- we can hardly require it... -->
1.22      avankest  756: 
1.60      avankest  757:      <li>
                    758:       <p>Switch the object to the <a href="#open" title="OPEN state">OPEN</a>
1.106     avankest  759:        state, set the <a href="#send-flag"><code>send()</code> flag</a> to
1.105     avankest  760:        "false" and then synchronously dispatch a <code><a
1.60      avankest  761:        href="#dfn-readystatechange">readystatechange</a></code> event on the
1.97      avankest  762:        object and return the method call.
1.60      avankest  763:     </ol>
1.24      avankest  764: 
1.25      avankest  765:     <p class=note>A future version or extension of this specification will
1.35      avankest  766:      most likely define a way of doing cross-site requests.</p>
1.26      avankest  767: 
1.25      avankest  768:    <dt><dfn id=dfn-setrequestheader
                    769:     title=setrequestheader><code>setRequestHeader(<var>header</var>,
1.18      avankest  770:     <var>value</var>)</code></dfn>, method
1.6       avankest  771: 
                    772:    <dd>
1.47      avankest  773:     <p>Each request has a list of request headers with associated values.
                    774:      This method can be used to manipulate those values and set new request
                    775:      headers.</p>
                    776: 
1.60      avankest  777:     <p>When invoked, the user agent <em class=ct>must</em> follow the
1.97      avankest  778:      following steps (unless otherwise indicated):</p>
1.60      avankest  779: 
                    780:     <ol>
                    781:      <li>
                    782:       <p>If the state of the object is not <a href="#open" title="OPEN
1.97      avankest  783:        state">OPEN</a> raise an <code>INVALID_STATE_ERR</code> exception and
1.99      avankest  784:        terminate these steps.
1.6       avankest  785: 
1.60      avankest  786:      <li>
1.104     avankest  787:       <p>If the <a href="#send-flag"><code>send()</code> flag</a> is "true"
1.99      avankest  788:        raise an <code>INVALID_STATE_ERR</code> exception and terminate these
1.97      avankest  789:        steps.
1.60      avankest  790: 
                    791:      <li>
1.98      avankest  792:       <p>If the <var>header</var> argument does not match the <dfn
1.60      avankest  793:        id=field-name><code>field-name</code> production</dfn> as defined by
1.97      avankest  794:        section 4.2 of RFC 2616 or is <code>null</code> raise a
1.99      avankest  795:        <code>SYNTAX_ERR</code> exception and terminate these steps. [<cite><a
1.97      avankest  796:        href="#RFC2616">RFC2616</a></cite>]
1.71      avankest  797: 
                    798:      <li>
1.99      avankest  799:       <p>If the <var>value</var> argument is <code>null</code> terminate
                    800:        these steps. (Do not raise an exception.)
1.71      avankest  801:      </li>
                    802:      <!-- undefined is to be treated as null here... -->
1.60      avankest  803: 
                    804:      <li>
1.98      avankest  805:       <p>If the <var>value</var> argument does not match the <dfn
1.60      avankest  806:        id=field-value><code>field-value</code> production</dfn> as defined by
1.99      avankest  807:        section 4.2 of RFC 2616 raise a <code>SYNTAX_ERR</code> and terminate
1.97      avankest  808:        these steps. [<cite><a href="#RFC2616">RFC2616</a></cite>]
1.60      avankest  809: 
                    810:      <li>
1.99      avankest  811:       <p>For security reasons these steps <em class=ct>should</em> be
                    812:        terminated if the <var>header</var> argument <a
                    813:        href="#case-insensitive-match" title="case-insensitive
                    814:        match">case-insensitively matches</a> one of the following headers:</p>
1.34      avankest  815: 
                    816:       <ul>
                    817:        <li><code>Accept-Charset</code>
                    818: 
                    819:        <li><code>Accept-Encoding</code>
                    820: 
1.69      avankest  821:        <li><code>Connection</code>
                    822: 
1.34      avankest  823:        <li><code>Content-Length</code>
                    824: 
1.69      avankest  825:        <li><code>Content-Transfer-Encoding</code>
                    826: 
                    827:        <li><code>Date</code>
                    828: 
1.34      avankest  829:        <li><code>Expect</code>
                    830: 
                    831:        <li><code>Host</code>
                    832: 
                    833:        <li><code>Keep-Alive</code>
                    834: 
                    835:        <li><code>Referer</code>
                    836: 
                    837:        <li><code>TE</code>
                    838: 
                    839:        <li><code>Trailer</code>
                    840: 
                    841:        <li><code>Transfer-Encoding</code>
                    842: 
                    843:        <li><code>Upgrade</code>
1.69      avankest  844: 
                    845:        <li><code>Via</code>
1.34      avankest  846:       </ul>
1.6       avankest  847: 
1.60      avankest  848:      <li>
                    849:       <p>If the <var>header</var> argument is not in the list of request
1.97      avankest  850:        headers append the <var>header</var> with its associated
1.99      avankest  851:        <var>value</var> to the list and terminate these steps.
1.46      avankest  852: 
1.60      avankest  853:      <li>
                    854:       <p>If the <var>header</var> argument is in the list of request headers
1.97      avankest  855:        either use multiple headers, combine the values or use a combination
                    856:        of those (section 4.2, RFC 2616). [<cite><a
                    857:        href="#RFC2616">RFC2616</a></cite>]
                    858:      </li>
                    859:      <!-- XXX it seems UAs always combine the values -->
1.60      avankest  860:     </ol>
1.18      avankest  861: 
1.47      avankest  862:     <p class=note>See also the <code><a href="#dfn-send">send()</a></code>
                    863:      method regarding user agent header handling for caching, authentication,
                    864:      proxies, and cookies.</p>
                    865: 
1.25      avankest  866:     <div class=example>
1.60      avankest  867:      <pre><code>// The following script:
1.18      avankest  868: var client = new XMLHttpRequest();
                    869: client.open('GET', 'demo.cgi');
                    870: client.setRequestHeader('X-Test', 'one');
                    871: client.setRequestHeader('X-Test', 'two');
                    872: client.send();
                    873: 
                    874: // ...would result in the following header being sent:
                    875: ...
                    876: X-Test: one, two
1.60      avankest  877: ...</code></pre>
1.18      avankest  878:     </div>
1.6       avankest  879: 
1.25      avankest  880:    <dt><dfn id=dfn-send title=send><code>send(<var>data</var>)</code></dfn>,
                    881:     method
1.2       avankest  882: 
                    883:    <dd>
1.60      avankest  884:     <p>The <code><a href="#dfn-send">send()</a></code> method initiates the
1.107     avankest  885:      request and its optional argument provides the <a
                    886:      href="#dfn-entity-body">entity body</a>. Authors are strongly encouraged
                    887:      to ensure that they have specified the <code>Content-Type</code> header
                    888:      via <code><a href="#dfn-setrequestheader">setRequestHeader()</a></code>
                    889:      before invoking <code><a href="#dfn-send">send()</a></code> with a
                    890:      non-<code>null</code> <var>data</var> argument.</p>
1.60      avankest  891: 
                    892:     <p>When invoked, the user agent <em class=ct>must</em> follow the
1.109     avankest  893:      following steps (unless otherwise noted). Note that this algorithm might
1.110     avankest  894:      get aborted if the <code><a href="#dfn-open">open()</a></code> or
                    895:      <code><a href="#dfn-abort">abort()</a></code> is invoked. When the <dfn
                    896:      id=abort-send-algorithm title="abort send()"><code>send()</code>
1.111     avankest  897:      algorithm is aborted</dfn> the user agent <em class=ct>must</em>
                    898:      terminate the algorithm after finishing the step it is on.</p>
1.109     avankest  899: 
                    900:     <p class=note>The following algorithm can not be aborted through script
                    901:      when <var>async</var> is <code>false</code>. It can only be aborted when
                    902:      <var>async</var> is <code>true</code> and only after the method call has
                    903:      returned.</p>
1.60      avankest  904: 
                    905:     <ol>
                    906:      <li>
                    907:       <p>If the state of the object is not <a href="#open" title="OPEN
1.97      avankest  908:        state">OPEN</a> raise an <code>INVALID_STATE_ERR</code> exception and
1.99      avankest  909:        terminate these steps.
1.60      avankest  910: 
                    911:      <li>
1.104     avankest  912:       <p>If the <a href="#send-flag"><code>send()</code> flag</a> is "true"
1.99      avankest  913:        raise an <code>INVALID_STATE_ERR</code> exception and terminate these
1.97      avankest  914:        steps.
1.60      avankest  915: 
                    916:      <li>
1.104     avankest  917:       <p>If <var>async</var> is <code>true</code> set the <a
                    918:        href="#send-flag"><code>send()</code> flag</a> to "true".
1.103     avankest  919: 
                    920:      <li>
1.60      avankest  921:       <p>If the <var>data</var> argument has not been omitted and is not
1.97      avankest  922:        <code>null</code> use it for the <dfn id=dfn-entity-body>entity
                    923:        body</dfn> as defined by section 7.2 of RFC 2616 observing the
                    924:        following rules: [<cite><a href="#RFC2616">RFC2616</a></cite>]</p>
1.60      avankest  925: 
                    926:       <dl>
                    927:        <dt><var>data</var> is a <code>DOMString</code>
                    928: 
1.79      avankest  929:        <dd>
1.97      avankest  930:         <p>Encode <var>data</var> using UTF-8 for transmission.
1.60      avankest  931: 
                    932:        <dt><var>data</var> is a <code>Document</code>
                    933: 
                    934:        <dd>
1.97      avankest  935:         <p>Serialize <var>data</var> into a namespace well-formed XML
                    936:          document and encoded using the encoding given by
                    937:          <code><var>data</var>.xmlEncoding</code>, if specified, or UTF-8
                    938:          otherwise. Or, if this fails because the <code>Document</code>
                    939:          cannot be serialized act as if <var>data</var> is <code>null</code>.</p>
                    940: 
                    941:         <p>If no <code>Content-Type</code> header is in the list of request
                    942:          headers append it to the list of request headers with a value of
                    943:          <code>application/xml</code>.</p>
1.60      avankest  944: 
                    945:         <p class=note>Subsequent changes to the <code>Document</code> have no
                    946:          effect on what is submitted.</p>
                    947: 
                    948:        <dt><var>data</var> is not a <code>DOMString</code> or
                    949:         <code>Document</code>
                    950: 
1.79      avankest  951:        <dd>
1.97      avankest  952:         <p>Use the stringification mechanisms of the host language on
                    953:          <var>data</var> and treat the result as if <var>data</var> is a
                    954:          <code>DOMString</code>. Or, if this fails, act as if <var>data</var>
                    955:          is <code>null</code>.
1.60      avankest  956:       </dl>
                    957: 
                    958:       <p>If the data argument has been omitted or is <code>null</code> no
1.97      avankest  959:        entity body is used in the request.</p>
1.60      avankest  960: 
                    961:      <li>
1.72      avankest  962:       <p>Make a request to <var>stored url</var>, using HTTP method
                    963:        <var>stored method</var>, user <var>stored user</var> (if provided)
                    964:        and password <var>stored password</var> (if provided), taking into
                    965:        account the entity body, list of request headers and the rules listed
                    966:        directly after this set of steps.
1.60      avankest  967: 
                    968:      <li>
1.97      avankest  969:       <p>Synchronously dispatch a <code><a
                    970:        href="#dfn-readystatechange">readystatechange</a></code> event on the
                    971:        object.</p>
                    972: 
                    973:       <p class=note>The state of the object does not change. The event is
                    974:        dispatched for historical reasons.</p>
1.68      avankest  975: 
                    976:      <li>
1.103     avankest  977:       <p>If <var>async</var> is <code>true</code> return the <code><a
                    978:        href="#dfn-send">send()</a></code> method call. (Do not terminate the
                    979:        steps in the algorithm though.)
1.60      avankest  980: 
                    981:      <li>
1.83      avankest  982:       <p>If the request has been successfully acknowledged synchronously
1.105     avankest  983:        switch the state to <a href="#sent" title="SENT state">SENT</a>, set
                    984:        the <a href="#send-flag"><code>send()</code> flag</a> to "false" and
1.97      avankest  985:        then synchronously dispatch a <code><a
                    986:        href="#dfn-readystatechange">readystatechange</a></code> event on the
                    987:        object.
1.60      avankest  988: 
                    989:      <li>
1.102     avankest  990:       <p>If all HTTP headers have been received, immediately before receiving
                    991:        the message body (if any), synchronously switch the state to <a
                    992:        href="#loading" title="LOADING state">LOADING</a> and then
1.97      avankest  993:        synchronously dispatch a <code><a
1.60      avankest  994:        href="#dfn-readystatechange">readystatechange</a></code> event on the
                    995:        object.
                    996: 
                    997:      <li>
                    998:       <p>If the response is an HTTP redirect (status code <code>301</code>,
1.97      avankest  999:        <code>302</code>, <code>303</code> or <code>307</code>), transparently
                   1000:        follow it (unless it violates security, infinite loop precautions or
                   1001:        the scheme is not supported).</p>
1.60      avankest 1002: 
                   1003:       <p class=note>HTTP places requirements on the user agent regarding the
                   1004:        preservation of the request method and entity body during redirects,
                   1005:        and also requires users to be notified of certain kinds of automatic
                   1006:        redirections.</p>
                   1007:       <!-- Arguably HTTP should be fixed for the latter case. No browser
                   1008:       follows that as far as I know. -->
                   1009:       
                   1010: 
                   1011:      <li>
1.97      avankest 1012:       <p>If something goes wrong (infinite loop, network errors) run the
                   1013:        following set of steps:</p>
1.60      avankest 1014: 
                   1015:       <ol>
                   1016:        <li>
1.97      avankest 1017:         <p>Set <a href="#response-entity-body">response entity body</a> to
                   1018:          "null" and reset the list of request headers.
1.60      avankest 1019: 
                   1020:        <li>
1.83      avankest 1021:         <p>Synchronously switch the state to <a href="#done" title="DONE
                   1022:          state">DONE</a>.
1.60      avankest 1023: 
                   1024:        <li>
1.97      avankest 1025:         <p>If <var>async</var> is set to <code>false</code> raise a <code><a
1.100     avankest 1026:          href="#network-err">NETWORK_ERR</a></code> exception and terminate
                   1027:          the overall algorithm.
1.60      avankest 1028: 
                   1029:        <li>
                   1030:         <p>Synchronously dispatch a <code><a
                   1031:          href="#dfn-readystatechange">readystatechange</a></code> event on
                   1032:          the object.
                   1033: 
                   1034:        <li>
1.99      avankest 1035:         <p>Terminate the overall algorithm.
1.60      avankest 1036:       </ol>
                   1037: 
1.83      avankest 1038:       <p class=note>It is likely that a future version of the <code><a
                   1039:        href="#xmlhttprequest-object">XMLHttpRequest</a></code> object will
                   1040:        dispatch an <code>error</code> event here as well.</p>
1.60      avankest 1041: 
                   1042:      <li>
1.83      avankest 1043:       <p>When the request has successfully completed loading, synchronously
1.97      avankest 1044:        switch the state to <a href="#done" title="DONE state">DONE</a> and
                   1045:        then synchronously dispatch a <code><a
                   1046:        href="#dfn-readystatechange">readystatechange</a></code> event on the
                   1047:        object and return the method call in case of <var>async</var> being
                   1048:        <code>false</code>.
1.60      avankest 1049:     </ol>
1.19      avankest 1050: 
1.92      avankest 1051:     <p>If the user agent allows the user to configure a proxy it <em
1.25      avankest 1052:      class=ct>should</em> modify the request appropriately; <abbr title="in
1.2       avankest 1053:      other words">i.e.</abbr>, connect to the proxy host instead of the
                   1054:      origin server, modify the <code>Request-Line</code> and send
                   1055:      <code>Proxy-Authorization</code> headers as specified.</p>
                   1056: 
1.44      avankest 1057:     <p>If the user agent supports HTTP Authentication it <em
                   1058:      class=ct>should</em> consider requests originating from this object to
                   1059:      be part of the protection space that includes the accessed URIs and send
1.19      avankest 1060:      <code>Authorization</code> headers and handle <code>401
1.73      avankest 1061:      Unauthorised</code> requests appropriately. If authentication fails,
1.44      avankest 1062:      user agents <em class=ct>should</em> prompt the users for credentials.
                   1063:      [<cite><a href="#ref-rfc2617">RFC2617</a></cite>]</p>
1.19      avankest 1064: 
1.59      avankest 1065:     <p>If the user agent supports HTTP State Management it <em
1.44      avankest 1066:      class=ct>should</em> persist, discard and send cookies (as received in
                   1067:      the <code>Set-Cookie</code> and <code>Set-Cookie2</code> response
                   1068:      headers, and sent in the <code>Cookie</code> header) as applicable.
1.51      avankest 1069:      [<cite><a href="#ref-rfc2965">RFC2965</a></cite>]</p>
1.44      avankest 1070: 
                   1071:     <p>If the user agent implements a HTTP cache it <em class=ct>should</em>
                   1072:      respect <code>Cache-Control</code> request headers set by the script
                   1073:      (<abbr title="for example">e.g.</abbr>, <code>Cache-Control:
                   1074:      no-cache</code> bypasses the cache). It <em class=ct>must not</em> send
1.25      avankest 1075:      <code>Cache-Control</code> or <code>Pragma</code> request headers
1.44      avankest 1076:      automatically unless the user explicitly requests such behaviour
                   1077:      (<abbr>e.g.</abbr>, by (force-)reloading the page). <code>304 Not
                   1078:      Modified</code> responses that are a result of a user agent generated
                   1079:      conditional request <em class=ct>must</em> be presented as <code>200
1.59      avankest 1080:      OK</code> responses with the appropriate content. The user agent <em
1.44      avankest 1081:      class=ct>must</em> allow scripts to override automatic cache validation
                   1082:      by setting request headers (e.g., <code>If-None-Match</code>,
1.16      avankest 1083:      <code>If-Modified-Since</code>), in which case <code>304 Not
1.44      avankest 1084:      Modified</code> responses <em class=ct>must</em> be passed through.
                   1085:      [<cite><a href="#RFC2616">RFC2616</a></cite>]</p>
1.2       avankest 1086: 
1.44      avankest 1087:     <p>If the user agent implements server-driven content-negotiation it <em
1.25      avankest 1088:      class=ct>should</em> set <code>Accept-Language</code>,
1.18      avankest 1089:      <code>Accept-Encoding</code> and <code>Accept-Charset</code> headers as
1.25      avankest 1090:      appropriate; it <em class=ct>must not</em> automatically set the
1.18      avankest 1091:      <code>Accept</code> header. Responses to such requests <em
1.44      avankest 1092:      class=ct>must</em> have the content-codings automatically decoded.
                   1093:      [<cite><a href="#RFC2616">RFC2616</a></cite>]</p>
1.18      avankest 1094: 
1.25      avankest 1095:    <dt><dfn id=dfn-abort><code>abort()</code></dfn>, method
1.6       avankest 1096: 
                   1097:    <dd>
1.62      avankest 1098:     <p>When invoked, the user agent <em class=ct>must</em> run the following
1.97      avankest 1099:      steps (unless otherwise noted):</p>
1.6       avankest 1100: 
1.62      avankest 1101:     <ol>
                   1102:      <li>
1.109     avankest 1103:       <p><a href="#abort-send-algorithm" title="abort send()">Abort the
                   1104:        <code>send()</code> algorithm</a>, set the <a
                   1105:        href="#response-entity-body">response entity body</a> to "null", set
                   1106:        the <a href="#send-flag"><code>send()</code> flag</a> to "false" and
                   1107:        remove any registered request headers.
1.62      avankest 1108: 
                   1109:      <li>
1.109     avankest 1110:       <p>The user agent <em class=ct>should</em> cancel any network activity
                   1111:        for which the object is responsible.
1.62      avankest 1112: 
1.80      avankest 1113:      <li>
1.86      avankest 1114:       <p>If the state is <a href="#unsent" title="UNSENT state">UNSENT</a>,
1.84      avankest 1115:        <a href="#open" title="OPEN state">OPEN</a> and the <a
1.104     avankest 1116:        href="#send-flag"><code>send()</code> flag</a> is "false", or <a
1.86      avankest 1117:        href="#done" title="DONE state">DONE</a> go to the next step.</p>
1.84      avankest 1118: 
                   1119:       <p>Otherwise, switch the state to <a href="#done" title="DONE
1.97      avankest 1120:        state">DONE</a> and synchronously dispatch a <code><a
1.84      avankest 1121:        href="#dfn-readystatechange">readystatechange</a></code> event on the
                   1122:        object.</p>
1.68      avankest 1123: 
1.62      avankest 1124:      <li>
1.72      avankest 1125:       <p>Switch the state to <a href="#unsent" title="UNSENT
1.98      avankest 1126:        state">UNSENT</a>. (Do not dispatch the <code><a
1.62      avankest 1127:        href="#dfn-readystatechange">readystatechange</a></code> event.)</p>
                   1128: 
1.83      avankest 1129:       <p class=note>It is likely that a future version of the <code><a
                   1130:        href="#xmlhttprequest-object">XMLHttpRequest</a></code> object will
                   1131:        dispatch an <code title="">abort</code> event here as well.</p>
1.62      avankest 1132:     </ol>
1.26      avankest 1133: 
1.6       avankest 1134:    <dt><dfn
1.25      avankest 1135:     id=dfn-getallresponseheaders><code>getAllResponseHeaders()</code></dfn>,
1.13      avankest 1136:     method
1.2       avankest 1137: 
                   1138:    <dd>
1.62      avankest 1139:     <p>When invoked, the user agent <em class=ct>must</em> run the following
                   1140:      steps:</p>
1.60      avankest 1141: 
                   1142:     <ol>
1.77      avankest 1143:      <li>
1.87      avankest 1144:       <p>If the state is not <a href="#loading" title="LOADING
1.97      avankest 1145:        state">LOADING</a> or <a href="#done" title="DONE state">DONE</a>
1.99      avankest 1146:        raise an <code>INVALID_STATE_ERR</code> exception and terminate these
1.97      avankest 1147:        steps.
1.77      avankest 1148: 
                   1149:      <li>
1.97      avankest 1150:       <p>Return all the HTTP headers, as a single string, with each header
                   1151:        line separated by a U+000D CR U+000A LF pair excluding the status
                   1152:        line.
1.60      avankest 1153:     </ol>
1.6       avankest 1154: 
1.25      avankest 1155:     <div class=example>
1.60      avankest 1156:      <pre><code>// The following script:
1.6       avankest 1157: var client = new XMLHttpRequest();
1.18      avankest 1158: client.open("GET", "test.txt", true);
1.6       avankest 1159: client.send();
1.16      avankest 1160: client.onreadystatechange = function() {
1.17      avankest 1161:  if(this.readyState == 3) {
1.16      avankest 1162:   print(this.getAllResponseHeaders());
                   1163:  }
                   1164: }
1.6       avankest 1165: 
                   1166: // ...should output something similar to the following text:
                   1167: Date: Sun, 24 Oct 2004 04:58:38 GMT
                   1168: Server: Apache/1.3.31 (Unix)
                   1169: Keep-Alive: timeout=15, max=99
                   1170: Connection: Keep-Alive
                   1171: Transfer-Encoding: chunked
1.60      avankest 1172: Content-Type: text/plain; charset=utf-8</code></pre>
1.6       avankest 1173:     </div>
                   1174: 
1.25      avankest 1175:    <dt><dfn id=dfn-getresponseheader
                   1176:     title=getresponseheader><code>getResponseHeader(<var>header</var>)</code></dfn>,
1.13      avankest 1177:     method
1.2       avankest 1178: 
1.6       avankest 1179:    <dd>
1.60      avankest 1180:     <p>When the method is invoked, the user agent <em class=ct>must</em> run
                   1181:      the following steps:</p>
                   1182: 
                   1183:     <ol>
1.77      avankest 1184:      <li>
1.87      avankest 1185:       <p>If the state is not <a href="#loading" title="LOADING
1.97      avankest 1186:        state">LOADING</a> or <a href="#done" title="DONE state">DONE</a>
1.99      avankest 1187:        raise an <code>INVALID_STATE_ERR</code> exception and terminate these
1.97      avankest 1188:        steps.
1.17      avankest 1189: 
1.77      avankest 1190:      <li>
1.98      avankest 1191:       <p>If the <var>header</var> argument does not match the <a
1.97      avankest 1192:        href="#field-name"><code>field-name</code> production</a> raise a
1.99      avankest 1193:        <code>SYNTAX_ERR</code> exception and terminate these steps.
1.77      avankest 1194: 
                   1195:      <li>
1.81      avankest 1196:       <p>If the <var>header</var> argument <a href="#case-insensitive-match"
                   1197:        title="case-insensitive match">case-insensitively matches</a> multiple
1.97      avankest 1198:        HTTP headers for the last request sent return the values of these
                   1199:        headers as a single concatenated string separated from each other by
1.99      avankest 1200:        an U+002C COMMA followed by an U+0020 SPACE and terminate these steps.
1.77      avankest 1201: 
                   1202:      <li>
1.81      avankest 1203:       <p>If the <var>header</var> argument <a href="#case-insensitive-match"
                   1204:        title="case-insensitive match">case-insensitively matches</a> a single
1.97      avankest 1205:        HTTP header for the last request sent return the value of that header
1.99      avankest 1206:        and terminate these steps.
1.77      avankest 1207: 
                   1208:      <li>
1.97      avankest 1209:       <p>Return <code>null</code>.
1.60      avankest 1210:     </ol>
1.17      avankest 1211: 
1.25      avankest 1212:     <div class=example>
1.60      avankest 1213:      <pre><code>// The following script:
1.1       avankest 1214: var client = new XMLHttpRequest();
1.18      avankest 1215: client.open("GET", "test.txt", true);
1.6       avankest 1216: client.send();
1.16      avankest 1217: client.onreadystatechange = function() {
1.17      avankest 1218:  if(this.readyState == 3) {
1.18      avankest 1219:   print(client.getResponseHeader("Content-Type"));
1.16      avankest 1220:  }
                   1221: }
1.1       avankest 1222: 
1.6       avankest 1223: // ...should output something similar to the following text:
1.60      avankest 1224: Content-Type: text/plain; charset=utf-8</code></pre>
1.2       avankest 1225:     </div>
                   1226: 
1.25      avankest 1227:    <dt><dfn id=dfn-responsetext><code>responseText</code></dfn> of type
1.9       avankest 1228:     <code>DOMString</code>, readonly
1.6       avankest 1229: 
                   1230:    <dd>
1.89      avankest 1231:     <p>On getting, the user agent <em class=ct>must</em> run the following
                   1232:      steps:</p>
                   1233: 
                   1234:     <ol>
                   1235:      <li>
                   1236:       <p>If the state is not <a href="#loading" title="LOADING
1.97      avankest 1237:        state">LOADING</a> or <a href="#done" title="DONE state">DONE</a>
1.99      avankest 1238:        raise an <code>INVALID_STATE_ERR</code> exception and terminate these
1.97      avankest 1239:        steps.
1.6       avankest 1240: 
1.89      avankest 1241:      <li>
                   1242:       <p>Return the <a href="#text-response-entity-body">text response entity
                   1243:        body</a>.
                   1244:     </ol>
1.12      avankest 1245: 
1.25      avankest 1246:    <dt><dfn id=dfn-responsexml><code>responseXML</code></dfn> of type
1.9       avankest 1247:     <code>Document</code>, readonly
1.6       avankest 1248: 
                   1249:    <dd>
1.76      avankest 1250:     <p>On getting, the user agent <em class=ct>must</em> run the following
                   1251:      steps:</p>
                   1252: 
                   1253:     <ol>
                   1254:      <li>
1.97      avankest 1255:       <p>If the state is not <a href="#done" title="DONE state">DONE</a>
1.99      avankest 1256:        raise an <code>INVALID_STATE_ERR</code> exception and terminate these
1.97      avankest 1257:        steps.
1.76      avankest 1258: 
                   1259:      <li>
1.89      avankest 1260:       <p>Return the <a href="#xml-response-entity-body">XML response entity
                   1261:        body</a>.
1.76      avankest 1262:     </ol>
1.12      avankest 1263: 
1.25      avankest 1264:    <dt><dfn id=dfn-status><code>status</code></dfn> of type <code>unsigned
1.9       avankest 1265:     short</code>, readonly
1.6       avankest 1266: 
                   1267:    <dd>
1.73      avankest 1268:     <p>On getting, if available, it <em class=ct>must</em> return the HTTP
                   1269:      status code sent by the server (typically <code>200</code> for a
                   1270:      successful request). Otherwise, if not available, the user agent <em
                   1271:      class=ct>must</em> raise an <code>INVALID_STATE_ERR</code> exception.</p>
1.12      avankest 1272: 
1.25      avankest 1273:    <dt><dfn id=dfn-statustext><code>statusText</code></dfn> of type
1.9       avankest 1274:     <code>DOMString</code>, readonly
1.2       avankest 1275: 
1.6       avankest 1276:    <dd>
1.73      avankest 1277:     <p>On getting, if available, it <em class=ct>must</em> return the HTTP
                   1278:      status text sent by the server (appears after the status code).
                   1279:      Otherwise, if not available, the user agent <em class=ct>must</em> raise
                   1280:      an <code>INVALID_STATE_ERR</code> exception.</p>
1.2       avankest 1281:   </dl>
                   1282: 
1.60      avankest 1283:   <h3 id=events><span class=secno>2.1. </span>Events for the <code
1.33      avankest 1284:    title="">XMLHttpRequest</code> Object</h3>
1.2       avankest 1285: 
1.1       avankest 1286:   <p>These sections describe the various events that can be dispatched on the
1.2       avankest 1287:    object implementing the <code><a
1.60      avankest 1288:    href="#xmlhttprequest-object">XMLHttpRequest</a></code> interface. For
                   1289:    this version of the specification only one event is defined.
1.2       avankest 1290: 
1.1       avankest 1291:   <dl>
1.25      avankest 1292:    <dt><dfn id=dfn-readystatechange><code>readystatechange</code></dfn>
1.2       avankest 1293: 
1.73      avankest 1294:    <dd>When the user agent dispatches a <code
                   1295:     title="">readystatechange</code> event (as indicated above) it <em
                   1296:     class=ct>must not</em> bubble, <em class=ct>must not</em> be cancelable
                   1297:     and <em class=ct>must</em> implement the <code>Event</code> interface.
                   1298:     Its <code>namespaceURI</code> attribute <em class=ct>must</em> be
                   1299:     <code>null</code>. [<cite><a href="#DOM3EV">DOM3Events</a></cite>]
1.1       avankest 1300:   </dl>
1.2       avankest 1301: 
1.60      avankest 1302:   <h3 id=exceptions><span class=secno>2.2. </span>Exceptions for the <code
1.33      avankest 1303:    title="">XMLHttpRequest</code> Object</h3>
                   1304: 
1.34      avankest 1305:   <pre
                   1306:    class=idl>exception <dfn id=xmlhttprequestexception>XMLHttpRequestException</dfn> {
1.33      avankest 1307:   unsigned short     code;
                   1308: };
                   1309: const unsigned short <a href="#network-err">NETWORK_ERR</a> = 101;</pre>
                   1310: 
1.35      avankest 1311:   <p>The <dfn id=network-err><code>NETWORK_ERR</code></dfn> exception is
                   1312:    thrown when a network error occurs in synchronous requests. See the
1.42      avankest 1313:    section on <code><a href="#dfn-send">send()</a></code> for more details.
1.33      avankest 1314: 
1.31      avankest 1315:   <h2 class=no-num id=notcovered>Not in this Specification</h2>
                   1316: 
                   1317:   <p><em>This section is non normative.</em>
                   1318: 
1.73      avankest 1319:   <p>This specification does not include the following features which are
                   1320:    being considered for a future version of this specification:
1.31      avankest 1321: 
                   1322:   <ul>
                   1323:    <li><code>load</code> event and <code>onload</code> attribute;
                   1324: 
                   1325:    <li><code>error</code> event and <code>onerror</code> attribute;
                   1326: 
                   1327:    <li><code>progress</code> event and <code>onprogress</code> attribute;
                   1328: 
                   1329:    <li><code title="">abort</code> event and <code>onabort</code> attribute;
                   1330: 
                   1331:    <li>Timers have been suggested, perhaps an <code>ontimeout</code>
                   1332:     attribute;
                   1333: 
                   1334:    <li>Property to disable following redirects;
                   1335: 
1.32      avankest 1336:    <li><code title="">responseXML</code> for <code>text/html</code>
                   1337:     documents;
1.31      avankest 1338: 
1.42      avankest 1339:    <li>Cross-site <code title="">XMLHttpRequest</code>;
                   1340: 
1.88      avankest 1341:    <li><code>responseBody</code> to deal with byte streams;
1.42      avankest 1342: 
1.115   ! avankest 1343:    <li><code>overrideMimeType</code> to fix up MIME types;
        !          1344: 
1.88      avankest 1345:    <li><code>getRequestHeader()</code> and
                   1346:     <code>removeRequestHeader()</code>.
1.31      avankest 1347:   </ul>
                   1348: 
1.25      avankest 1349:   <h2 class=no-num id=bibref>References</h2>
1.2       avankest 1350: 
1.7       avankest 1351:   <dl>
1.39      avankest 1352:    <dt>[<dfn id=DOM3>DOM3Core</dfn>]
1.2       avankest 1353: 
1.15      avankest 1354:    <dd><cite><a href="http://www.w3.org/TR/DOM-Level-3-Core">Document Object
                   1355:     Model (DOM) Level 3 Core Specification</a></cite>, A. Le Hors, P. Le
                   1356:     Hégaret, L. Wood, G. Nicol, J. Robie, M. Champion, S. Byrne, editors.
                   1357:     World Wide Web Consortium, April 2004.
1.2       avankest 1358: 
1.39      avankest 1359:    <dt>[<dfn id=DOM3EV>DOM3Events</dfn>]
1.2       avankest 1360: 
                   1361:    <dd><cite><a href="http://www.w3.org/TR/DOM-Level-3-Events/">Document
1.15      avankest 1362:     Object Model (DOM) Level 3 Events Specification</a></cite>, Björn
                   1363:     Höhrmann, editor. World Wide Web Consortium, April 2006.
                   1364: 
1.39      avankest 1365:    <dt>[<dfn id=ref-ecmascript>ECMAScript</dfn>]
1.18      avankest 1366: 
                   1367:    <dd><cite><a
                   1368:     href="http://www.ecma-international.org/publications/standards/Ecma-262.htm">ECMAScript
                   1369:     Language Specification</a></cite>, Third Edition. ECMA, December 1999.
                   1370: 
1.39      avankest 1371:    <dt>[<dfn id=ref-rfc2046>RFC2046</dfn>]
1.18      avankest 1372: 
1.22      avankest 1373:    <dd><cite><a href="http://ietf.org/rfc/rfc2046">Multipurpose Internet Mail
                   1374:     Extensions (MIME) Part Two: Media Types</a></cite>, N. Freed, N.
                   1375:     Borenstein, editors. IETF, November 1996.
1.18      avankest 1376: 
1.39      avankest 1377:    <dt>[<dfn id=RFC2119>RFC2119</dfn>]
1.15      avankest 1378: 
                   1379:    <dd><cite><a href="http://ietf.org/rfc/rfc2119">RFC 2119: Key words for
                   1380:     use in RFCs to Indicate Requirement Levels</a></cite>, S. Bradner. IETF,
                   1381:     March 1997.
                   1382: 
1.39      avankest 1383:    <dt>[<dfn id=RFC2616>RFC2616</dfn>]
1.15      avankest 1384: 
                   1385:    <dd><cite><a href="http://ietf.org/rfc/rfc2616">Hypertext Transfer
                   1386:     Protocol -- HTTP/1.1</a></cite>, R. Fielding, J. Gettys, J. Mogul, H.
1.93      avankest 1387:     Frystyk, L. Masinter, P. Leach, T. Berners-Lee, editors. IETF, June 1999.
1.15      avankest 1388: 
1.39      avankest 1389:    <dt>[<dfn id=ref-rfc2617>RFC2617</dfn>]
1.15      avankest 1390: 
                   1391:    <dd><cite><a href="http://ietf.org/rfc/rfc2617">HTTP Authentication: Basic
1.93      avankest 1392:     and Digest Access Authentication</a></cite>, P. Hallam-Baker, J.
                   1393:     Hostetler, S. Lawrence, P. Leach, A. Luotonen, L. Stewart, editors. IETF,
                   1394:     June 1999.
1.2       avankest 1395: 
1.39      avankest 1396:    <dt>[<dfn id=ref-rfc2965>RFC2965</dfn>]
1.2       avankest 1397: 
1.22      avankest 1398:    <dd><cite><a href="http://ietf.org/rfc/rfc2965">HTTP State Management
                   1399:     Mechanism</a></cite>, D. Kristol, L. Montulli, editors. IETF, October
                   1400:     2000.
                   1401: 
1.39      avankest 1402:    <dt>[<dfn id=ref-rfc3986>RFC3986</dfn>]
1.2       avankest 1403: 
1.15      avankest 1404:    <dd><cite><a href="http://ietf.org/rfc/rfc3986">Uniform Resource
                   1405:     Identifier (URI): Generic Syntax</a></cite>, T. Berners-Lee, R. Fielding,
                   1406:     L. Masinter, editors. IETF, January 2005.
1.30      avankest 1407: 
1.39      avankest 1408:    <dt>[<dfn id=ref-window>Window</dfn>]
1.30      avankest 1409: 
                   1410:    <dd><cite><a href="http://www.w3.org/TR/Window/">Window Object
                   1411:     1.0</a></cite>, I. Davis, M. Stachowiak, editors. W3C, April 2006.
1.43      avankest 1412: 
                   1413:    <dt>[<dfn id=ref-xml>XML</dfn>]
                   1414: 
                   1415:    <dd><cite><a href="http://www.w3.org/TR/xml/">Extensible Markup Language
                   1416:     (XML) 1.0 (Fourth Edition)</a></cite>, T. Bray, J. Paoli, C.
                   1417:     Sperberg-McQueen, E. Maler, F. Yergeau. W3C, September 2006.
                   1418: 
                   1419:    <dt>[<dfn id=ref-xmlns>XMLNS</dfn>]
                   1420: 
                   1421:    <dd><cite><a href="http://www.w3.org/TR/xml-names/">Namespaces in XML
                   1422:     (Second Edition)</a></cite>, T. Bray, D. Hollander, A. Layman, R. Tobin.
                   1423:     W3C, August 2006.
1.2       avankest 1424:   </dl>
                   1425: 
1.25      avankest 1426:   <h2 class=no-num id=acknowledgements>Acknowledgements</h2>
1.2       avankest 1427: 
                   1428:   <p><em>This section is non-normative</em>
                   1429: 
1.9       avankest 1430:   <p>The editor would like to thank to the following people who have
1.35      avankest 1431:    contributed to this specification (ordered by first name):
1.2       avankest 1432: 
1.1       avankest 1433:   <ul>
1.113     avankest 1434:    <li>Ahmed Kamel
                   1435: 
1.25      avankest 1436:    <li>Alex Hopmann
                   1437: 
1.9       avankest 1438:    <li>Alex Vincent
                   1439: 
1.19      avankest 1440:    <li>Alexey Proskuryakov
                   1441: 
1.2       avankest 1442:    <li>Asbjørn Ulsberg
                   1443: 
                   1444:    <li>Boris Zbarsky
                   1445: 
                   1446:    <li>Björn Höhrmann
                   1447: 
                   1448:    <li>Cameron McCormack
                   1449: 
                   1450:    <li>Christophe Jolif
                   1451: 
                   1452:    <li>Charles McCathieNevile
                   1453: 
1.56      avankest 1454:    <li>Dan Winship
                   1455: 
1.73      avankest 1456:    <li>David Håsäther
                   1457: 
1.2       avankest 1458:    <li>Dean Jackson
                   1459: 
                   1460:    <li>Doug Schepers
                   1461: 
                   1462:    <li>Douglas Livingstone
                   1463: 
1.113     avankest 1464:    <li>Eric Lawrence
                   1465: 
                   1466:    <li>Gideon Cohn
                   1467: 
1.2       avankest 1468:    <li>Gorm Haug Eriksen
                   1469: 
                   1470:    <li>Hallvord R. M. Steen
                   1471: 
                   1472:    <li>Håkon Wium Lie
                   1473: 
                   1474:    <li>Ian Davis
                   1475: 
                   1476:    <li>Ian Hickson
                   1477: 
                   1478:    <li>Ivan Herman
                   1479: 
                   1480:    <li>Jens Lindström
                   1481: 
                   1482:    <li>Jim Deegan
                   1483: 
                   1484:    <li>Jim Ley
                   1485: 
1.113     avankest 1486:    <li>Joe Farro
                   1487: 
1.2       avankest 1488:    <li>Jonas Sicking
                   1489: 
                   1490:    <li>Julian Reschke
                   1491: 
                   1492:    <li>Karl Dubost
                   1493: 
                   1494:    <li>Maciej Stachowiak
                   1495: 
1.9       avankest 1496:    <li>Magnus Kristiansen
                   1497: 
1.2       avankest 1498:    <li>Marc Hadley
                   1499: 
1.55      avankest 1500:    <li>Marcos Caceres
                   1501: 
1.88      avankest 1502:    <li>Mark Baker
                   1503: 
1.2       avankest 1504:    <li>Mark Nottingham
                   1505: 
1.93      avankest 1506:    <li>Mohamed Zergaoui
                   1507: 
1.2       avankest 1508:    <li>Pawel Glowacki
                   1509: 
                   1510:    <li>Robin Berjon
                   1511: 
                   1512:    <li>Ruud Steltenpool
1.35      avankest 1513: 
                   1514:    <li>Simon Pieters
1.113     avankest 1515: 
                   1516:    <li>Sunava Dutta
                   1517: 
                   1518:    <li>Zhenbin Xu
1.1       avankest 1519:   </ul>
1.2       avankest 1520: 
                   1521:   <p>Special thanks to the Microsoft employees who first implemented the
1.60      avankest 1522:    <code><a href="#xmlhttprequest-object">XMLHttpRequest</a></code>
                   1523:    interface, which was first widely deployed by the Windows Internet
                   1524:    Explorer browser.
1.2       avankest 1525: 
1.56      avankest 1526:   <p>Special thanks also to the WHATWG for drafting an initial version of
                   1527:    this specification in their Web Applications 1.0 document.
1.2       avankest 1528: 
                   1529:   <p>Thanks also to all those who have helped to improve this specification
                   1530:    by sending suggestions and corrections. (Please, keep bugging us with your
                   1531:    issues!)

Webmaster