Annotation of 2006/webapi/XMLHttpRequest/Overview.src.html, revision 1.207
1.60 avankest 1: <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
1.1 avankest 2: <html lang="en-US">
3: <head>
1.207 ! avankest 4: <title>XMLHttpRequest</title>
1.16 avankest 5: <style type="text/css">
1.117 avankest 6: pre.idl { border:solid thin; background:#eee; color:#000; padding:0.5em }
1.16 avankest 7: pre.idl :link, pre.idl :visited { color:inherit; background:transparent }
1.58 avankest 8: pre code { color:inherit; background:transparent }
1.16 avankest 9: div.example { margin-left:1em; padding-left:1em; border-left:double; color:#222; background:#fcfcfc }
1.89 avankest 10: .note { margin-left:2em; font-weight:bold; font-style:italic; color:#008000 }
1.16 avankest 11: p.note::before { content:"Note: " }
1.203 avankest 12: .XXX { padding:.5em; border:solid #f00 }
13: p.XXX::before { content:"Issue: " }
1.119 avankest 14: dl.switch { padding-left:2em }
15: dl.switch dt { text-indent:-1.5em }
16: dl.switch dt:before { content:'21円AA'; padding:0 0.5em 0 0; display:inline-block; width:1em; text-align:right; line-height:0.5em }
1.16 avankest 17: em.ct { text-transform:lowercase; font-variant:small-caps; font-style:normal }
18: dfn { font-weight:bold; font-style:normal }
19: code { color:orangered }
20: code :link, code :visited { color:inherit }
1.203 avankest 21: hr:not(.top) { display:block; background:none; border:none; padding:0; margin:2em 0; height:auto }
22: table { border-collapse:collapse; border-style:hidden hidden none hidden }
23: table thead { border-bottom:solid }
24: table tbody th:first-child { border-left:solid }
25: table td, table th { border-left:solid; border-right:solid; border-bottom:solid thin; vertical-align:top; padding:0.2em }
1.16 avankest 26: </style>
1.147 avankest 27: <link rel="stylesheet" href="http://www.w3.org/StyleSheets/TR/W3C-[STATUS]">
1.1 avankest 28: </head>
29: <body>
30: <div class="head">
31: <p><a href="http://www.w3.org/"><img height="48" width="72" alt="W3C" src="http://www.w3.org/Icons/w3c_home"></a></p>
1.12 avankest 32:
1.207 ! avankest 33: <h1 class="head" id="the-xmlhttprequest-object"><code title="">XMLHttpRequest</code></h1>
1.12 avankest 34:
1.149 avankest 35: <h2 class="no-num no-toc" id="w3c-doctype">[LONGSTATUS] [DATE: 3 August 2002]</h2>
1.12 avankest 36:
1.1 avankest 37: <dl>
1.10 avankest 38: <dt>This Version:</dt>
1.173 avankest 39: <dd><a href="[VERSION]/">http://www.w3.org/TR/[YEAR]/ED-XMLHttpRequest-[CDATE]/</a></dd>
1.14 avankest 40:
1.10 avankest 41: <dt>Latest Version:</dt>
1.1 avankest 42: <dd><a href="http://www.w3.org/TR/XMLHttpRequest/">http://www.w3.org/TR/XMLHttpRequest/</a></dd>
1.203 avankest 43:
1.189 avankest 44: <dt>Latest Editor Version:</dt>
45: <dd><a href="http://dev.w3.org/2006/webapi/XMLHttpRequest/">http://dev.w3.org/2006/webapi/XMLHttpRequest/</a></dd>
1.14 avankest 46:
1.10 avankest 47: <dt>Previous Versions:</dt>
1.173 avankest 48: <dd><a href="http://www.w3.org/TR/2008/WD-XMLHttpRequest-20080415/">http://www.w3.org/TR/2008/WD-XMLHttpRequest-20080415/</a></dd>
1.154 avankest 49: <dd><a href="http://www.w3.org/TR/2007/WD-XMLHttpRequest-20071026/">http://www.w3.org/TR/2007/WD-XMLHttpRequest-20071026/</a></dd>
1.133 avankest 50: <dd><a href="http://www.w3.org/TR/2007/WD-XMLHttpRequest-20070618/">http://www.w3.org/TR/2007/WD-XMLHttpRequest-20070618/</a></dd>
1.58 avankest 51: <dd><a href="http://www.w3.org/TR/2007/WD-XMLHttpRequest-20070227/">http://www.w3.org/TR/2007/WD-XMLHttpRequest-20070227/</a></dd>
1.22 avankest 52: <dd><a href="http://www.w3.org/TR/2006/WD-XMLHttpRequest-20060927/">http://www.w3.org/TR/2006/WD-XMLHttpRequest-20060927/</a></dd>
1.1 avankest 53: <dd><a href="http://www.w3.org/TR/2006/WD-XMLHttpRequest-20060619/">http://www.w3.org/TR/2006/WD-XMLHttpRequest-20060619/</a></dd>
54: <dd><a href="http://www.w3.org/TR/2006/WD-XMLHttpRequest-20060405/">http://www.w3.org/TR/2006/WD-XMLHttpRequest-20060405/</a></dd>
1.14 avankest 55:
1.1 avankest 56: <dt>Editor:</dt>
57: <dd><a href="http://annevankesteren.nl/">Anne van Kesteren</a>
58: (<a href="http://www.opera.com/">Opera Software ASA</a>)
59: <<a href="mailto:annevk@opera.com">annevk@opera.com</a>></dd>
60: </dl>
1.14 avankest 61:
1.1 avankest 62: <p class="copyright"><a href="http://www.w3.org/Consortium/Legal/ipr-notice#Copyright">Copyright</a>
1.51 avankest 63: © 2007
64: <a href="http://www.w3.org/"><acronym title="World Wide Web Consortium">W3C</acronym></a><sup>®</sup>
65: (<a href="http://www.csail.mit.edu/"><acronym title="Massachusetts Institute of Technology">MIT</acronym></a>,
66: <a href="http://www.ercim.org/"><acronym title="European Research Consortium for Informatics and Mathematics">ERCIM</acronym></a>,
67: <a href="http://www.keio.ac.jp/">Keio</a>), All Rights Reserved. W3C
68: <a href="http://www.w3.org/Consortium/Legal/ipr-notice#Legal_Disclaimer">liability</a>,
69: <a href="http://www.w3.org/Consortium/Legal/ipr-notice#W3C_Trademarks">trademark</a>
70: and
71: <a href="http://www.w3.org/Consortium/Legal/copyright-documents">document
72: use</a> rules apply.</p>
1.1 avankest 73: </div>
1.12 avankest 74:
1.1 avankest 75: <hr>
1.12 avankest 76:
1.207 ! avankest 77:
! 78:
1.1 avankest 79: <h2 class="no-num no-toc" id="specabstract">Abstract</h2>
1.10 avankest 80:
1.207 ! avankest 81: <p>The <code title="">XMLHttpRequest</code> specification defines an API
! 82: that provides scripted client functionality for transferring data between
! 83: a client and a server.</p>
! 84:
! 85:
1.12 avankest 86:
1.1 avankest 87: <h2 class="no-num no-toc" id="sotd">Status of this Document</h2>
1.12 avankest 88:
1.1 avankest 89: <p><em>This section describes the status of this document at the time of its
1.36 avankest 90: publication. Other documents may supersede this document. A list of current
91: W3C publications and the latest revision of this technical report can be
92: found in the <a href="http://www.w3.org/TR/">W3C technical reports index</a>
1.117 avankest 93: at http://www.w3.org/TR/.</em></p>
1.36 avankest 94:
1.207 ! avankest 95: <p>This is the [DATE: 3 August 2002] [LONGSTATUS] of the
! 96: <code title="">XMLHttpRequest</code> specification. Please send comments
! 97: to <a href="mailto:public-webapps@w3.org">public-webapps@w3.org</a>
! 98: (<a href="http://lists.w3.org/Archives/Public/public-webapps/">archived</a>)
1.172 avankest 99: with either <samp>[XHR]</samp> or <samp title="">[XMLHttpRequest]</samp>
1.207 ! avankest 100: at the start of the subject line<!-- before befor 2 June 2008-->.</p>
1.51 avankest 101:
1.47 avankest 102: <p>This document is produced by the
1.207 ! avankest 103: <a href="http://www.w3.org/2008/webapps/">Web Applications</a> (WebApps)
! 104: Working Group, part of the
! 105: <a href="http://www.w3.org/2006/rwc/Activity">Rich Web Clients Activity</a>
! 106: in the W3C <a href="http://www.w3.org/Interaction/">Interaction Domain</a>.
! 107: Changes made to this document can be found in the
1.47 avankest 108: <a href="http://dev.w3.org/cvsweb/2006/webapi/XMLHttpRequest/Overview.html">W3C
1.117 avankest 109: public CVS server</a>.</p>
1.12 avankest 110:
1.1 avankest 111: <p>Publication as a Working Draft does not imply endorsement by the W3C
1.36 avankest 112: Membership. This is a draft document and may be updated, replaced or
113: obsoleted by other documents at any time. It is inappropriate to cite this
114: document as other than work in progress.</p>
1.12 avankest 115:
1.1 avankest 116: <p>This document was produced by a group operating under the
1.36 avankest 117: <a href="http://www.w3.org/Consortium/Patent-Policy-20040205/">5 February
1.52 avankest 118: 2004 W3C Patent Policy</a>. W3C maintains a
1.207 ! avankest 119: <a rel="disclosure" href="http://www.w3.org/2004/01/pp-impl/42538/status">public
1.36 avankest 120: list of any patent disclosures</a> made in connection with the deliverables
121: of the group; that page also includes instructions for disclosing a patent.
122: An individual who has actual knowledge of a patent which the individual
123: believes contains
124: <a href="http://www.w3.org/Consortium/Patent-Policy-20040205/#def-essential">Essential
125: Claim(s)</a> must disclose the information in accordance with
126: <a href="http://www.w3.org/Consortium/Patent-Policy-20040205/#sec-Disclosure">section
127: 6 of the W3C Patent Policy</a>.</p>
1.12 avankest 128:
1.207 ! avankest 129:
! 130:
1.1 avankest 131: <h2 class="no-num no-toc" id="toc">Table of Contents</h2>
1.21 avankest 132:
1.1 avankest 133: <!--toc-->
1.12 avankest 134:
1.207 ! avankest 135:
! 136:
1.1 avankest 137: <h2 id="introduction">Introduction</h2>
1.12 avankest 138:
1.1 avankest 139: <p><em>This section is non-normative.</em></p>
1.12 avankest 140:
1.183 avankest 141: <p>The <code>XMLHttpRequest</code> object implements an interface exposed
142: by a scripting engine that allows scripts to perform HTTP client
143: functionality, such as submitting form data or loading data from a
144: server. It is the ECMAScript HTTP API.</p>
1.24 avankest 145:
1.1 avankest 146: <p>The name of the object is <code>XMLHttpRequest</code> for compatibility
1.183 avankest 147: with the Web, though each component of this name is potentially
148: misleading. First, the object supports any text based format, including
149: XML. Second, it can be used to make requests over both HTTP and HTTPS
150: (some implementations support protocols in addition to HTTP and HTTPS, but
151: that functionality is not covered by this specification). Finally, it
152: supports "requests" in a broad sense of the term as it pertains to HTTP;
153: namely all activity involved with HTTP requests or responses for the
154: defined HTTP methods.</p>
1.12 avankest 155:
1.14 avankest 156: <div class="example">
157: <p>Some simple code to do something with data from an XML document fetched
1.22 avankest 158: over the network:</p>
1.16 avankest 159:
1.58 avankest 160: <pre><code>function test(data) {
1.14 avankest 161: // taking care of data
162: }
163:
164: function handler() {
1.117 avankest 165: if(this.readyState == 4 && this.status == 200) {
1.14 avankest 166: // so far so good
1.117 avankest 167: if(this.responseXML != null && this.responseXML.getElementById('test').firstChild.data)
168: // success!
1.14 avankest 169: test(this.responseXML.getElementById('test').firstChild.data);
170: else
171: test(null);
1.117 avankest 172: } else if (this.readyState == 4 && this.status != 200) {
1.14 avankest 173: // fetched the wrong page or network error...
174: test(null);
175: }
176: }
1.12 avankest 177:
1.14 avankest 178: var client = new XMLHttpRequest();
179: client.onreadystatechange = handler;
180: client.open("GET", "test.xml");
1.58 avankest 181: client.send();</code></pre>
1.16 avankest 182:
1.56 avankest 183: <p>If you just want to log a message to the server:</p>
1.16 avankest 184:
1.58 avankest 185: <pre><code>function log(message) {
1.14 avankest 186: var client = new XMLHttpRequest();
1.56 avankest 187: client.open("POST", "/log");
1.57 avankest 188: client.setRequestHeader("Content-Type", "text/plain;charset=UTF-8");
1.14 avankest 189: client.send(message);
1.58 avankest 190: }</code></pre>
1.16 avankest 191:
1.14 avankest 192: <p>Or if you want to check the status of a document on the server:</p>
1.16 avankest 193:
1.58 avankest 194: <pre><code>function fetchStatus(address) {
1.14 avankest 195: var client = new XMLHttpRequest();
196: client.onreadystatechange = function() {
197: // in case of network errors this might not give reliable results
198: if(this.readyState == 4)
199: returnStatus(this.status);
200: }
201: client.open("HEAD", address);
202: client.send();
1.58 avankest 203: }</code></pre>
1.14 avankest 204: </div>
1.12 avankest 205:
1.203 avankest 206:
207:
1.153 avankest 208: <h2 id="conformance">Conformance</h2>
1.12 avankest 209:
1.27 avankest 210: <p>Everything in this specification is normative except for diagrams,
211: examples, notes and sections marked non-normative.</p>
1.12 avankest 212:
1.1 avankest 213: <p>The key words <em class="ct">must</em>, <em class="ct">must not</em>,
1.74 avankest 214: <em class="ct">should</em> and <em class="ct">may</em> in this document are
215: to be interpreted as described in RFC 2119.
216: [<cite><span>RFC2119</span></cite>]</p>
1.12 avankest 217:
1.1 avankest 218: <p>This specification defines the following classes of products:</p>
1.12 avankest 219:
1.1 avankest 220: <dl>
1.74 avankest 221: <dt><dfn id="conforming-user-agent">Conforming user agent</dfn></dt>
1.24 avankest 222:
1.74 avankest 223: <dd>
224: <p>A user agent <em class="ct">must</em> behave as described in this
1.106 avankest 225: specification in order to be considered conformant.</p>
1.95 avankest 226:
1.140 avankest 227: <p>If the user agent is not a conforming XML user agent the <span>XML
228: response entity body</span> <em class="ct">must</em> (always) be
229: <code>null</code>.</p>
230:
231: <p>User agents <em class="ct">may</em> implement algorithms given in
232: this specification in any way desired, so long as the end result is
233: indistinguishable from the result that would be obtained by the
234: specification's algorithms.</p>
1.110 avankest 235:
1.95 avankest 236: <p class="note">This specification uses both the terms "conforming user
237: agent(s)" and "user agent(s)" to refer to this product class.</p>
1.74 avankest 238: </dd>
1.110 avankest 239:
1.94 avankest 240: <dt><dfn id="conforming-xml-user-agent">Conforming XML user agent</dfn></dt>
1.110 avankest 241:
1.163 avankest 242: <dd><p>An XML user agent <em class="ct">must</em> be a <span>conforming
243: user agent</span> and <em class="ct">must</em> be a conforming XML
244: processor that reports violations of namespace well-formedness.
1.203 avankest 245: [<cite><span>XML</span></cite>]</p></dd>
1.1 avankest 246: </dl>
1.32 avankest 247:
1.203 avankest 248:
1.153 avankest 249: <h3 id="dependencies">Dependencies</h3>
1.33 avankest 250:
1.29 avankest 251: <p>This specification relies on several underlying specifications.</p>
252: <dl>
253: <dt>DOM</dt>
1.33 avankest 254:
1.155 avankest 255: <dd><p>A <span title="conforming user agent">conforming user agent</span>
1.176 avankest 256: <em class="ct">must</em> support at least the subset of the functionality
1.182 avankest 257: defined in DOM Events and DOM Core that this specification relies upon,
258: such as various exceptions and <code>EventTarget</code>.
1.155 avankest 259: [<cite><span>DOM2Events</span></cite>]
260: [<cite><span>DOM3Core</span></cite>]</p></dd>
1.29 avankest 261:
1.161 avankest 262: <dt>HTML 5</dt>
263:
264: <dd>
1.189 avankest 265: <p>A <span>conforming user agent</span> <em class="ct">must</em> support
266: at least the subset of the functionality defined in HTML 5 that
1.197 avankest 267: this specification relies upon, such as the basics of the
268: <code>Window</code> object and serializing a <code>Document</code>
269: object. [<cite><span>HTML5</span></cite>]</p>
1.161 avankest 270:
271: <p class="note">The
272: <a href="http://www.w3.org/TR/2006/WD-Window-20060407/">Window Object
273: 1.0</a> draft is not referenced normatively as it appears to be no
274: longer maintained and HTML 5 defines the <code>Window</code> object
275: in more detail. This specification already depends on HTML 5 for
276: other reasons so there is not much additional overhead because of
277: this.</p>
278:
1.29 avankest 279: <dt>HTTP</dt>
1.33 avankest 280:
1.29 avankest 281: <dd>
1.155 avankest 282: <p>A <span>conforming user agent</span>
1.126 avankest 283: <em class="ct">must</em> support some version of the HTTP protocol. It
284: <em class="ct">should</em> support any HTTP method that matches the
1.203 avankest 285: <span>Method token</span> and <em class="ct">must</em>
1.149 avankest 286: at least support the following methods:</p>
1.58 avankest 287:
288: <ul>
289: <li><code>GET</code></li>
290: <li><code>POST</code></li>
291: <li><code>HEAD</code></li>
292: <li><code>PUT</code></li>
293: <li><code>DELETE</code></li>
294: <li><code>OPTIONS</code></li>
295: </ul>
1.135 avankest 296:
1.58 avankest 297: <p>Other requirements regarding HTTP are made throughout the
1.39 avankest 298: specification. [<cite><span>RFC2616</span></cite>]</p>
1.29 avankest 299: </dd>
1.189 avankest 300:
1.181 avankest 301: <dt>Web IDL</dt>
1.203 avankest 302:
1.181 avankest 303: <dd>A <span>conforming user agent</span> <em class="ct">must</em> also be
304: a conforming implementation of the IDL fragment in this specification, as
305: described in the Web IDL specification.
306: [<cite><span>WebIDL</span></cite>]
1.29 avankest 307: </dl>
1.12 avankest 308:
1.157 avankest 309:
1.153 avankest 310: <h3 id="terminology">Terminology</h3>
1.203 avankest 311:
312: <!-- XXX define simple terms here instead of referencing them -->
1.12 avankest 313:
1.200 avankest 314: <p>The terms and algorithms
315: <dfn id="url-fragment"><fragment></dfn>,
316: <dfn id="url-scheme"><scheme></dfn>,
317: <dfn id="ascii-case-insensitive">ASCII case-insensitive</dfn>,
318: <dfn id="uppercase" title="uppercase">converting a string to uppercase</dfn>,
1.203 avankest 319: <dfn id="document-base-url">document base URL</dfn>,
1.205 avankest 320: <dfn id="event-handler-attributes-0">event handler attributes</dfn>,
1.203 avankest 321: <dfn id="event-handler-event-type">event handler event type</dfn>,
322: <dfn id="fully-active">fully active</dfn>,
1.206 avankest 323: <dfn id="function"><code>Function</code></dfn>,
1.200 avankest 324: <dfn id="origin">origin</dfn>,
1.203 avankest 325: <dfn id="resolve-a-url">resolve a URL</dfn>,
326: <dfn id="same-origin">same origin</dfn>,
327: <dfn id="storage-mutex">storage mutex</dfn>,
328: <dfn id="task">task</dfn>,
329: <dfn id="task-source">task source</dfn>,
330: <dfn id="url">URL</dfn>,
331: <dfn id="url-character-encoding">URL character encoding</dfn>, and
332: <dfn id="queue-a-task">queue a task</dfn>
1.200 avankest 333: are defined by the HTML 5 specification.
1.157 avankest 334: [<cite><span>HTML5</span></cite>]</p>
1.203 avankest 335:
336: <!-- Things might be splitted out of HTML5 -->
337:
338: <p>The term <dfn id="entity-body">entity body</dfn> is used as described
339: in RFC 2616. <dfn id="method-token">Method token</dfn> is used as
340: described in section 5.1.1 of RFC 2616. <dfn><code>field-name</code></dfn>
341: and <dfn><code>field-value</code></dfn> are used as described in section
342: 4.2 of RFC 2616. [<cite><span>RFC2616</span></cite>]</p>
343:
344: <p><dfn><code>userinfo</code></dfn> is used as described in section 3.2.1
345: of RFC 3986. [<cite><span>RFC3986</span></cite>]</p>
346:
347: <p>To <dfn id="dispatch-readystatechange-event">dispatch a
348: <code>readystatechange</code> event</dfn> means that an event with the
349: name <code>readystatechange</code>, with no namespace, which does not
350: bubble and is not cancelable, and which uses the <code>Event</code>
351: interface, <em class="ct">must</em> be dispatched at the
352: <code>XMLHttpRequest</code> object.</p>
1.155 avankest 353:
1.80 avankest 354:
1.153 avankest 355: <h3 id="extensibility">Extensibility</h3>
1.12 avankest 356:
1.81 avankest 357: <p>Extensions of the API defined by this specification are <em>strongly
1.22 avankest 358: discouraged</em>. User agents, Working Groups and other interested parties
1.33 avankest 359: should discuss extensions on a relevant public forum, preferably
1.22 avankest 360: <a href="mailto:public-webapi@w3.org">public-webapi@w3.org</a>.</p>
1.12 avankest 361:
1.153 avankest 362:
1.157 avankest 363:
1.153 avankest 364: <h2 id="security">Security Considerations</h2>
1.203 avankest 365:
366: <p>Security related requirements are made throughout this
367: specification.</p>
1.153 avankest 368:
369:
1.157 avankest 370:
1.153 avankest 371: <h2 id="xmlhttprequest">The <code title="">XMLHttpRequest</code>
372: Object</h2>
1.12 avankest 373:
1.58 avankest 374: <p>The <code>XMLHttpRequest</code> object can be used by scripts to
1.22 avankest 375: programmatically connect to their originating server via HTTP.</p>
1.12 avankest 376:
1.203 avankest 377: <pre class="idl">[<span title="XMLHttpRequest constructor">Constructor</span>,
378: Implements=EventTarget]
379: interface <dfn id="xmlhttprequest-object">XMLHttpRequest</dfn> {
1.206 avankest 380: // <a href="#event-handler-attributes">event handler attributes</a>
381: attribute <span>Function</span> <span>onreadystatechange</span>;
1.58 avankest 382:
1.205 avankest 383: // <a href="#states">states</a>
1.71 avankest 384: const unsigned short <span title="UNSENT state">UNSENT</span> = 0;
1.134 avankest 385: const unsigned short <span title="OPENED state">OPENED</span> = 1;
1.123 avankest 386: const unsigned short <span title="HEADERS_RECEIVED state">HEADERS_RECEIVED</span> = 2;
1.86 avankest 387: const unsigned short <span title="LOADING state">LOADING</span> = 3;
1.117 avankest 388: const unsigned short <span title="DONE state">DONE</span> = 4;
1.70 avankest 389: readonly attribute unsigned short <span>readyState</span>;
1.58 avankest 390:
1.205 avankest 391: // <a href="#request">request</a>
1.203 avankest 392: void <span>open</span>(in DOMString <var>method</var>, in DOMString <var title="">url</var>);
393: void <span>open</span>(in DOMString <var>method</var>, in DOMString <var title="">url</var>, in boolean <var>async</var>);
394: void <span>open</span>(in DOMString <var>method</var>, in DOMString <var title="">url</var>, in boolean <var>async</var>, [Null=Null, Undefined=Null] in DOMString <var>user</var>);
395: void <span>open</span>(in DOMString <var>method</var>, in DOMString <var title="">url</var>, in boolean <var>async</var>, [Null=Null, Undefined=Null] in DOMString <var>user</var>, [Null=Null, Undefined=Null] in DOMString <var>password</var>);
1.70 avankest 396: void <span>setRequestHeader</span>(in DOMString <var>header</var>, in DOMString <var>value</var>);
397: void <span>send</span>();
1.181 avankest 398: void <span>send</span>([Null=Null, Undefined=Null] in DOMString <var>data</var>);
1.70 avankest 399: void <span>send</span>(in Document <var>data</var>);
400: void <span>abort</span>();
1.58 avankest 401:
1.205 avankest 402: // <a href="#response">response</a>
1.203 avankest 403: readonly attribute unsigned short <span>status</span>;
404: readonly attribute DOMString <span>statusText</span>;
405: DOMString <span>getResponseHeader</span>(in DOMString <var>header</var>);
1.70 avankest 406: DOMString <span>getAllResponseHeaders</span>();
407: readonly attribute DOMString <span>responseText</span>;
408: readonly attribute Document <span>responseXML</span>;
1.1 avankest 409: };</pre>
1.8 avankest 410:
1.124 avankest 411:
1.203 avankest 412: <h3>Origin and Base URL</h3>
413:
414: <p>Each <code>XMLHttpRequest</code> object has an associated
415: <dfn id="xmlhttprequest-origin"><code>XMLHttpRequest</code> origin</dfn>
416: and an
417: <dfn id="xmlhttprequest-base-url"><code>XMLHttpRequest</code> base URL</dfn>.
418:
419: <p>This specification defines their values when the global object is
420: represented by the <code>Window</code> object. When the
421: <code>XMLHttpRequest</code> object used in other contexts their values
422: will have to be defined as appropriate for that context. That is
423: considered to be out of scope for this specification.</p>
424:
425: <hr>
426:
427: <p>In environments where the global object is represented by the
428: <code>Window</code> object the <code>XMLHttpRequest</code> object has an
429: associated
430: <dfn id="xmlhttprequest-document"><code>XMLHttpRequest</code> <code>Document</code></dfn>
431: which is the <code>Document</code> object associated with the
432: <code>Window</code> object for which the <code>XMLHttpRequest</code>
433: interface object was created.</p>
434:
435: <p class="note">The
436: <span><code>XMLHttpRequest</code> <code>Document</code></span> is used to
437: determine the <span><code>XMLHttpRequest</code> origin</span> and
438: <span><code>XMLHttpRequest</code> base URL</span> at a later stage.</p>
439:
440: <!-- XXX what happens if the document is not fully active?
441: e.g. should the constructor throw?
442: -->
443:
444:
445: <h3>Task Sources</h3>
446:
447: <p>The following <span title="task source">task sources</span> are used by
448: this specification:</p>
449:
450: <dl>
451: <dt>The <dfn><code>XMLHttpRequest</code> event task source</dfn></dt>
452:
453: <dd>This <span>task source</span> is used for events that are to be
454: asynchronously dispatched.</dd>
455:
456: <dt>The <dfn><code>XMLHttpRequest</code> networking task source</dfn></dt>
457:
458: <dd>This <span>task source</span> is used for network activity.</dd>
459: </dl>
460:
461: <p>Unless otherwise stated the <span>task source</span> used for all tasks
462: <span title="queue a task">queued</span> in this specification is the
463: <span><code>XMLHttpRequest</code> event task source</span>.</p>
464:
465:
466: <h3>Constructor</h3>
467:
468: <p>When the
469: <dfn id="xmlhttprequest-constructor" title="XMLHttpRequest constructor"><code title="">XMLHttpRequest()</code></dfn>
470: constructor is invoked, the user agent <em class="ct">must</em> return a
471: new <code>XMLHttpRequest</code> object.</p>
472:
473:
1.205 avankest 474: <h3 id="event-handler-attributes">Event Handler Attributes</h3>
475:
476: <p>The following is the
477: <span title="event handler attributes">event handler attribute</span> (and
478: its corresponding <span>event handler event type</span>) that
479: <em class="ct">must</em> be supported as DOM attribute by the
480: <code>XMLHttpRequest</code> object:</p>
481:
482: <table>
483: <thead>
484: <tr>
485: <th><span title="event handler attributes">event handler attribute</span>
486: <th><span>event handler event type</span>
487: <tbody>
488: <tr>
489: <td><dfn id="onreadystatechange"><code>onreadystatechange</code></dfn>
490: <td><code>readystatechange</code></td>
491: </table>
492:
493:
494: <h3 id="states">States</h3>
1.203 avankest 495:
496: <p>The <code>XMLHttpRequest</code> object can be in several states. The
497: <dfn id="readystate"><code>readyState</code></dfn> attribute, on getting,
498: <em class="ct">must</em> return the current state, which
499: <em class="ct">must</em> be one of the following values:</p>
500:
501: <dl>
502: <dt><dfn id="unsent-state" title="UNSENT state"><code>UNSENT</code></dfn>
503: (numeric value 0)</dt>
504: <dd><p>The object has been constructed.</p></dd>
505:
506: <dt><dfn id="opened-state" title="OPENED state"><code>OPENED</code></dfn>
507: (numeric value 1)</dt>
508: <dd><p>The <code>open()</code> method has been successfully invoked.
509: During this state request headers can be set using
510: <code>setRequestHeader()</code> and the request can be made using the
511: <code>send()</code> method.</p></dd>
512:
513: <dt><dfn id="headers-received-state" title="HEADERS_RECEIVED state"><code>HEADERS_RECEIVED</code></dfn>
514: (numeric value 2)</dt>
515: <dd><p>All HTTP headers have been received. Several response members of
516: the object are now available.</p></dd>
517:
518: <dt><dfn id="loading-state" title="LOADING state"><code>LOADING</code></dfn>
519: (numeric value 3)</dt>
520: <dd><p>The <span>response entity body</span> is being received.</p></dd>
521:
522: <dt><dfn id="done-state" title="DONE state"><code>DONE</code></dfn>
523: (numeric value 4)</dt>
524: <dd><p>The data transfer has been completed or something went wrong
525: during the transfer (e.g. infinite redirects).</p></dd>
526: </dl>
527:
528: <p>The <span title="OPENED state">OPENED</span> state has an associated
529: <dfn id="send-flag"><code>send()</code> flag</dfn> that indicates whether
530: the <code>send()</code> method has been invoked. It can be either true
531: or false and has an initial value of false.</p>
532:
533: <p>The <span title="DONE state">DONE</span> state has an associated
534: <dfn id="error-flag">error flag</dfn> that indicates some type of network
535: error or abortion. It can be either true or false and has an initial value
536: of false.</p>
537:
538:
1.205 avankest 539: <h3 id="request">Request</h3>
1.203 avankest 540:
541: <p>The <code>XMLHttpRequest</code> object holds the following request
542: metadata variables:</p>
543:
1.204 avankest 544: <dl>
545: <dt>The <dfn>asynchronous flag</dfn></dt>
546: <dd>A flag that is either true or false that indicates whether the
547: request is done asynchronously.</dd>
548:
549: <dt>The <dfn>request method</dfn></dt>
550: <dd>The method used in the request.</dd>
551:
552: <dt>The <dfn>request URL</dfn></dt>
553: <dd>The <span>URL</span> used in the request.</dd>
554:
555: <dt>The <dfn>request username</dfn></dt>
556: <dd>The username used in the request or null if there is no
557: username.</dd>
558:
559: <dt>The <dfn>request password</dfn></dt>
560: <dd>The password used in the request or null if there is no
561: password.</dd>
562:
563: <dt>The <dfn id="author-request-headers">author request headers</dfn></dt>
564: <dd>A list consisting of HTTP header name/value pairs to be used in the
565: request.</p>
1.203 avankest 566:
1.204 avankest 567: <dt>The <dfn>request entity body</dfn></dt>
568: <dd>The <span>entity body</span> used in the request.</dd>
569: </dl>
1.203 avankest 570:
571:
572: <h4>The <code title="">open()</code> method</h4>
1.88 avankest 573:
1.203 avankest 574: <p>When the <dfn id="open" title="open"><code>open(<var>method</var>,
575: <var title="">url</var>, <var>async</var>, <var>user</var>,
576: <var>password</var>)</code></dfn> method is invoked, the user agent
577: <em class="ct">must</em> run the following steps (unless otherwise
578: indicated):</p>
1.90 avankest 579:
1.88 avankest 580: <ol>
1.203 avankest 581: <li>
582: <p>If the <code>XMLHttpRequest</code> object has an associated
583: <span><code>XMLHttpRequest</code> <code>Document</code></span> run
584: these substeps:</p>
1.90 avankest 585:
1.203 avankest 586: <ol>
587: <li><p>If the
588: <span><code>XMLHttpRequest</code> <code>Document</code></span> is not
589: <span>fully active</span> raise an <code>INVALID_STATE_ERR</code>
590: exception and terminate the overall set of steps.</p></li>
591:
592: <li><p>Let <span><code>XMLHttpRequest</code> base URL</span> be the
593: <span>document base URL</span> of the
594: <span><code>XMLHttpRequest</code> <code>Document</code></span>.</p></li>
595:
596: <li><p>Let <span><code>XMLHttpRequest</code> origin</span> be the
597: <span>origin</span> of the
598: <span><code>XMLHttpRequest</code> <code>Document</code></span>.</p></li>
599: </ol>
600: </li>
1.90 avankest 601:
1.203 avankest 602: <li><p>If <var>method</var> does not match the
603: <span>Method token</span> raise a <code>SYNTAX_ERR</code> exception and
604: terminate these steps.</p></li>
1.118 avankest 605:
1.115 avankest 606: <li>
1.203 avankest 607: <p>If <var>method</var> is an
608: <span>ASCII case-insensitive</span> match for
609: <code>CONNECT</code>, <code>DELETE</code>, <code>GET</code>,
610: <code>HEAD</code>, <code>OPTIONS</code>, <code>POST</code>,
611: <code>PUT</code>, <code>TRACE</code>, or <code>TRACK</code>
612: <span title="uppercase">convert <var>method</var> to uppercase</span>.</p>
1.118 avankest 613:
1.203 avankest 614: <p class="note">If it does not match any of the above, it is passed
615: through <em>literally</em>, including in the final request.</p>
1.115 avankest 616: </li>
1.203 avankest 617: <!-- WebKit (and supposedly Gecko) also uppercase: COPY, INDEX, LOCK,
618: M-POST, MKCOL, MOVE, PROPFIND, PROPPATCH, and UNLOCK. -->
1.118 avankest 619:
1.111 avankest 620: <li>
1.203 avankest 621: <p>If <var>method</var> is one of <code>CONNECT</code>,
622: <code>TRACE</code>, or <code>TRACK</code> the user agent
623: <em class="ct">should</em> raise a <code>SECURITY_ERR</code> exception
624: and terminate these steps.</p>
1.117 avankest 625:
1.203 avankest 626: <p class="note">Allowing these methods poses a security risk.
627: [<cite><span>HTTPVERBSEC</span></cite>]</p>
1.111 avankest 628: </li>
629:
1.203 avankest 630: <li><p>Let <var title="">url</var> be a <span>URL</span>.</p></li>
631:
632: <li><p>Let <span>URL character encoding</span> of <var title="">url</var> be
1.113 avankest 633: UTF-8.</p></li>
634:
1.203 avankest 635: <li><p><span title="Resolve a URL">Resolve <var title="">url</var></span>
636: relative to the <span><code>XMLHttpRequest</code> base URL</span>.
637: If the algorithm returns an error raise a <code>SYNTAX_ERR</code>
638: exception and terminate these steps.</p></li>
639:
640: <!-- Presto and Gecko override the encoding. WebKit does not. Trident
641: does not support non-ASCII URLs. This matters for the <query> component,
642: see HTML5. -->
643:
644: <li><p>Drop <code><fragment></code> from <var title="">url</var>.</p></li>
645:
646: <li><p>If <var title="">url</var> contains an unsupported <code><scheme></code>
647: raise a <code>NOT_SUPPORTED_ERR</code> and terminate these
648: steps.</p></li>
649:
650: <li><p>If the <code>"user:password"</code> format in the
651: <code>userinfo</code> production is not supported for the relevant scheme
652: and <var title="">url</var> contains this format raise a
653: <code>SYNTAX_ERR</code> and terminate these steps.</p></li>
654:
655: <li><p>If <var title="">url</var> contains the <code>"user:password"</code>
656: format let <var>temp user</var> be the user part and
657: <var>temp password</var> be the password part.</p></li>
658:
659: <li><p>If <var title="">url</var> just contains the <code>"user"</code>
660: format let <var>temp user</var> be the user part.</p></li>
661:
662: <li><p>If the <span>origin</span> of <var title="">url</var> is not
663: <span>same origin</span> with the
664: <span><code>XMLHttpRequest</code> origin</span> the user agent
665: <em class="ct">should</em> raise a <code>SECURITY_ERR</code> exception
666: and terminate these steps.</p></li>
667:
668: <li><p>Let <var>async</var> be the value of the <var>async</var>
669: argument or <code>true</code> if it was omitted.</p></li>
670:
671: <li>
672: <p>If the <var>user</var> argument was not omitted follow these sub
673: steps:</p>
1.90 avankest 674:
1.203 avankest 675: <ol>
676: <li><p>If the syntax of <var>user</var> does not match the syntax
677: specified by the relevant authentication scheme, raise a
678: <code>SYNTAX_ERR</code> exception and terminate the overall set of
679: steps.</p></li>
1.163 avankest 680:
1.203 avankest 681: <li><p>If <var>user</var> is <code>null</code> let <var>temp user</var>
682: be null.</p></li>
1.90 avankest 683:
1.203 avankest 684: <li><p>Otherwise let <var>temp user</var> be <var>user</var>.</p></li>
685: </ol>
1.88 avankest 686:
1.203 avankest 687: <p class="note">These steps override anything that may have been set by
688: the <var title="">url</var> argument.</p>
689: </li>
1.88 avankest 690:
1.128 avankest 691: <li>
1.203 avankest 692: <p>If the <var>password</var> argument was not omitted follow these sub
693: steps:</p>
694:
695: <ol>
696: <li><p>If the syntax of <var>password</var> does not match the syntax
697: specified by the relevant authentication scheme, raise a
698: <code>SYNTAX_ERR</code> exception and terminate the overall set of
699: steps.</p></li>
1.167 avankest 700:
1.203 avankest 701: <li><p>If <var>password</var> is <code>null</code> let
702: <var>temp password</var> be null.</p></li>
703:
704: <li><p>Otherwise let <var>temp password</var> be
705: <var>password</var>.</p></li>
706: </ol>
707:
708: <p class="note">These steps override anything that may have been set by
709: the <var title="">url</var> argument.</p>
1.128 avankest 710: </li>
1.88 avankest 711:
1.203 avankest 712: <li><p><span title="abort send()">Abort the <code>send()</code> algorithm</span>.</p></li>
713:
714: <li><p>The user agent <em class="ct">should</em> cancel any network
715: activity for which the object is responsible.</p></li>
716: <!-- we can hardly require it... -->
717:
718: <li>
719: <p>Set variables associated with the object as follows:</p>
720:
721: <ul>
722: <li><p>Set the <span><code>send()</code> flag</span> to false.</p></li>
723:
724: <li><p>Set <span>response entity body</span> to null.</p></li>
725:
726: <li><p>Empty the list of <span>author request headers</span>.</p>
727:
728: <li><p>Set the <span>request method</span> to <var>method</var>.</p></li>
729:
730: <li><p>Set the <span>request URL</span> to <var title="">url</var>.</p></li>
1.58 avankest 731:
1.203 avankest 732: <li><p>Set the <span>request username</span> to <var>temp user</var>.</p></li>
1.12 avankest 733:
1.203 avankest 734: <li><p>Set the <span>request password</span> to <var>temp password</var>.</p></li>
1.12 avankest 735:
1.203 avankest 736: <li><p>Set the <span>asynchronous flag</span> to true if <var>async</var> is
737: <code>true</code>. Otherwise set it to false.</p></li>
738: </ul>
739: </li>
1.58 avankest 740:
1.203 avankest 741: <li><p>Switch the the state to
742: <span title="OPENED state">OPENED</span>.</p></li>
1.58 avankest 743:
1.203 avankest 744: <li><p><span>Dispatch a <code>readystatechange</code> event</span>.</p></li>
745: </ol>
1.14 avankest 746:
1.203 avankest 747: <p class="note">A future version or extension of this specification will
748: define a way of doing cross-origin requests.</p>
1.58 avankest 749:
1.14 avankest 750:
1.203 avankest 751: <h4>The <code title="">setRequestHeader()</code> method</h4>
1.12 avankest 752:
1.203 avankest 753: <!-- XXX authors
754: The <code>setRequestHeader()</code> method can be used to set new request
1.184 avankest 755: headers and append to request headers already in the list.</p>
1.203 avankest 756: -->
1.45 avankest 757:
1.203 avankest 758: <p>As indicated in the algorithm below certain headers cannot be set and
759: are left up to the user agent. In addition there are certain other headers
760: the user agent will take control of if they are not set by the author as
761: indicated at the end of the <code>send()</code> method section.</p>
762:
763: <p class="note">The <code>setRequestHeader()</code> method appends a
764: value if the HTTP header given as argument is already part of the
765: <span>author request headers</span> list.</p>
766:
767: <p>When the
768: <dfn id="setrequestheader" title="setrequestheader"><code>setRequestHeader(<var>header</var>,
769: <var>value</var>)</code></dfn> method is invoked, the user agent
770: <em class="ct">must</em> run the following steps (unless otherwise
771: indicated):</p>
1.14 avankest 772:
1.203 avankest 773: <ol>
774: <li><p>If the state is not <span title="OPENED state">OPENED</span> raise
775: an <code>INVALID_STATE_ERR</code> exception and terminate these
776: steps.</p></li>
777:
778: <li><p>If the <span><code>send()</code> flag</span> is true raise an
779: <code>INVALID_STATE_ERR</code> exception and terminate these
780: steps.</p></li>
781:
782: <li><p>If <var>header</var> does not match the <code>field-name</code>
783: production raise a <code>SYNTAX_ERR</code> exception and terminate these
784: steps.</p></li>
785:
786: <li>
787: <p>If the <var>value</var> argument does not match the
788: <code>field-value</code> production raise a <code>SYNTAX_ERR</code> and
789: terminate these steps.</p>
790:
791: <p class="note">The empty string is legal and represents the empty
792: header value.</p>
793: </li>
794:
795: <li>
796: <p>For security reasons, these steps <em class="ct">should</em> be
797: terminated if <var>header</var> is an
798: <span>ASCII case-insensitive</span> match for one of the following
799: headers:</p>
800:
801: <ul>
802: <li><code>Accept-Charset</code></li>
803: <li><code>Accept-Encoding</code></li>
804: <li><code>Authorization</code></li>
805: <li><code>Connection</code></li>
806: <li><code>Content-Length</code></li>
807: <li><code>Cookie</code></li>
808: <li><code>Cookie2</code></li>
809: <li><code>Content-Transfer-Encoding</code></li>
810: <li><code>Date</code></li>
811: <li><code>Expect</code></li>
812: <li><code>Host</code></li>
813: <li><code>Keep-Alive</code></li>
814: <li><code>Referer</code></li>
815: <li><code>TE</code></li>
816: <li><code>Trailer</code></li>
817: <li><code>Transfer-Encoding</code></li>
818: <li><code>Upgrade</code></li>
819: <li><code>User-Agent</code></li>
820: <li><code>Via</code></li>
821: </ul>
1.96 avankest 822:
1.203 avankest 823: <p>… or if the start of <var>header</var> is an
824: <span>ASCII case-insensitive</span> match for <code>Proxy-</code> or
825: <code>Sec-</code> (including when <var>header</var> is just
826: <code>Proxy-</code> or <code>Sec-</code>).</p>
827:
828: <p class="note">The above headers are not allowed to be set as they are
829: better controlled by the user agent as it knows best what value they
830: should have. Header names starting with <code>Sec-</code> are not
831: allowed to be set to allow new headers to be minted in the future that
832: are guaranteed not to come from <code>XMLHttpRequest</code>. (Older
833: clients would however still be vulnerable as they allow such headers to
834: be set.)</p>
835: </li>
1.14 avankest 836:
1.203 avankest 837: <li><p>If <var>header</var> is not in the
838: <span>author request headers</span> list append <var>header</var> with
839: its associated <var>value</var> to the list and terminate these
840: steps.</p></li>
841:
842: <li><p>If <var>header</var> is in the <span>author request headers</span>
843: list either use multiple headers, combine the values or use a combination
844: of those (section 4.2, RFC 2616).
845: [<cite><span>RFC2616</span></cite>]</p></li>
846: <!-- XXX it seems UAs always combine the values -->
847: </ol>
1.45 avankest 848:
1.203 avankest 849: <p class="note">See also the <code>send()</code> method regarding user
850: agent header handling for caching, authentication, proxies, and
851: cookies.</p>
1.14 avankest 852:
1.203 avankest 853: <div class="example">
854: <pre><code>// The following script:
1.14 avankest 855: var client = new XMLHttpRequest();
856: client.open('GET', 'demo.cgi');
857: client.setRequestHeader('X-Test', 'one');
858: client.setRequestHeader('X-Test', 'two');
859: client.send();
860:
861: // ...would result in the following header being sent:
862: ...
863: X-Test: one, two
1.58 avankest 864: ...</code></pre>
1.203 avankest 865: </div>
866:
867:
868: <h4>The <code title="">send()</code> method</h4>
1.12 avankest 869:
1.203 avankest 870: <p>The <code>send()</code> method initiates the request and its optional
1.204 avankest 871: argument provides the <span>request entity body</span>.</p>
1.12 avankest 872:
1.203 avankest 873: <p class="note">Authors are encouraged to ensure that they have specified
874: the <code>Content-Type</code> header via <code>setRequestHeader()</code>
875: before invoking <code>send()</code> with a non-<code>null</code>
876: <var>data</var> argument.</p>
877:
878: <p>When the
879: <dfn id="send" title="send"><code>send(<var>data</var>)</code></dfn>
880: method is invoked, the user agent <em class="ct">must</em> run the
881: following steps (unless otherwise noted). This algorithm gets aborted when
882: the <code>open()</code> or <code>abort()</code> method is invoked. When
883: the
884: <dfn title="abort send()" id="abort-send-algorithm"><code>send()</code> algorithm is aborted</dfn>
885: the user agent <em class="ct">must</em> terminate the algorithm after
886: finishing the step it is on.</p>
887:
888: <p class="note">The <code title="">send()</code> algorithm can only be
889: aborted when the <span>asynchronous flag</span> is true and only after the
890: method call has returned.</p>
1.181 avankest 891:
1.203 avankest 892: <ol>
893: <li><p>If the state is not <span title="OPENED state">OPENED</span> raise
894: an <code>INVALID_STATE_ERR</code> exception and terminate these
895: steps.</p></li>
896:
897: <li><p>If the <span><code>send()</code> flag</span> is true raise an
898: <code>INVALID_STATE_ERR</code> exception and terminate these
899: steps.</p></li>
1.58 avankest 900:
1.203 avankest 901: <li>
902: <p>If the <span>request method</var> is <code>GET</code> or
903: <code>HEAD</code> act as if <var>data</var> is <code>null</code>.</p>
1.96 avankest 904:
1.203 avankest 905: <p>If the <var>data</var> argument has not been omitted and is not
1.204 avankest 906: <code>null</code> use it for the <span>request entity body</span>
907: observing the following rules:</p>
1.203 avankest 908:
909: <dl class="switch">
910: <dt><var>data</var> is a <code>DOMString</code></dt>
911:
912: <dd>
913: <p>Encode <var>data</var> using UTF-8 for transmission.</p>
914:
915: <p>If a <code>Content-Type</code> header is set using
916: <code>setRequestHeader()</code> and its value is not malformed, set
917: the <code>charset</code> parameter of that header, by either
918: changing the <code>charset</code> parameter (if one is present) or
919: appending one, to <code>UTF-8</code>.</p>
920:
921: <p>If no <code>Content-Type</code> header has been set using
922: <code>setRequestHeader()</code> set a <code>Content-Type</code>
923: request header with a value of
924: <code>text/plain;charset=UTF-8</code>.</p>
925: </dd>
926:
927: <dt><var>data</var> is a <code>Document</code>
928:
929: <dd>
930: <p>Let <var>data</var> be <code><var>data</var>.innerHTML</code> as
931: defined by section 2.5 of HTML 5. Encode it using
932: <code><var>data</var>.inputEncoding</code> or UTF-8 if
933: <code><var>data</var>.inputEncoding</code> is
934: <code>null</code>. Re-raise any exceptions the
935: <code><var>data</var>.innerHTML</code> getter algorithm raises.
936: [<cite><span>HTML5</span></cite>]</p>
937: <!-- XXX this is completely bogus -->
938:
939: <p class="note">If the document cannot be serialized the
940: <code>document.innerHTML</code> algorithm raises an
941: <code>INVALID_STATE_ERR</code> exception.</p>
942:
943: <p>If a <code>Content-Type</code> header is set using
944: <code>setRequestHeader()</code> and its value is not malformed, set
945: the <code>charset</code> parameter of that header, by either
946: changing the <code>charset</code> parameter (if one is present) or
947: appending one, to the encoding used to encode the document.</p>
948:
949: <p>If no <code>Content-Type</code> header has been set using
950: <code>setRequestHeader()</code> set a <code>Content-Type</code>
951: request header with a value of
952: <code>application/xml;charset=<var>charset</var></code> where
953: <var>charset</var> is the encoding used to encode the document.</p>
954:
955: <p class="note">Subsequent changes to the <code>Document</code> have
956: no effect on what is submitted.</p>
957: </dd>
958:
959: <dt><var>data</var> is not a <code>DOMString</code> or
960: <code>Document</code></dt>
961:
962: <dd><p>Use the stringification mechanisms of the host language on
963: <var>data</var> and treat the result as if <var>data</var> is a
964: <code>DOMString</code>. Or, if this fails, act as if the
965: <var>data</var> argument is <code>null</code>.</p></dd>
966: <!-- XXX exceptions need to be re-raised -->
967: </dl>
1.58 avankest 968:
1.203 avankest 969: <p>If the <var>data</var> argument has been omitted, or is
1.204 avankest 970: <code>null</code>, no <span>request entity body</span> is used in the
971: request.</p>
1.203 avankest 972: </li>
1.202 avankest 973:
1.203 avankest 974: <li><p>If the <span>asynchronous flag</span> is false release the
975: <span>storage mutex</span>.</p></li>
1.103 avankest 976:
1.203 avankest 977: <li><p>If the <span>asynchronous flag</span> is true set the
978: <span><code>send()</code> flag</span> to true.</p></li>
1.118 avankest 979:
1.203 avankest 980: <li><p>Set the <span>error flag</span> to false.</p></li>
1.145 avankest 981:
1.203 avankest 982: <li>
983: <dl>
984: <dt>If the <span>asynchronous flag</span> is false</dt>
985: <dd>
986: <ol>
987: <li>
988: <p>Make a request to <span>request URL</span>, using HTTP method
989: <span>request method</span>, user <span>request username</span>
990: (if non-null) and password <span>request password</span> (if
1.204 avankest 991: non-null), taking into account the <span>request entity body</span>,
992: list of <span>author request headers</span> and the rules listed at
993: the end of this section.</p>
1.203 avankest 994:
995: <p>If there are cookies to be set, run these substeps:</p>
996:
1.118 avankest 997: <ol>
1.203 avankest 998: <li><p>Wait until ownership of the <span>storage mutex</span> can
999: be taken.</p></li>
1000:
1001: <li><p>Take ownership of the <span>storage mutex</span>.</p></li>
1002:
1003: <li><p>Update the cookies.
1004: [<cite><span>COOKIES</span></cite>]</p></li>
1005:
1006: <li><p>Release the <span>storage mutex</span> so that it is once
1007: again free.</p></li>
1008: </ol>
1.118 avankest 1009:
1.203 avankest 1010: <p>While making the request also follow the
1011: <span>request event rules</span>.</p>
1.118 avankest 1012:
1.203 avankest 1013: <p>When the request is completed and has not been terminated by the
1014: <span>request event rules</span> go to the next step.</p>
1015: </li>
1016: <!--
1017: This cannot involve any task queue whatsoever because that would
1018: mean other tasks on the task queue might get processed as well which
1019: is counter to the whole idea of doing things synchronous.
1020: -->
1021:
1022: <li>
1023: <p>If the overall algorithm has not been terminated at this stage
1024: the request was successful. Run these substeps:</p>
1.118 avankest 1025:
1.203 avankest 1026: <ol>
1027: <li><p>Switch the state to <span title="DONE state">DONE</span>.</p></li>
1.118 avankest 1028:
1.203 avankest 1029: <li><p><span>Dispatch a <code>readystatechange</code> event</span>.</p></li>
1.118 avankest 1030: </ol>
1.203 avankest 1031:
1032: <p class="note">The <code>send()</code> method call will now be
1033: returned by virtue of this algorithm ending.</p>
1034: </li>
1035: </ol>
1036: </dd>
1037:
1038: <dt>If the <span>asynchronous flag</span> is true</dt>
1039: <dd>
1040: <ol>
1041: <li>
1042: <p><span>Dispatch a <code>readystatechange</code> event</span>.</p>
1043:
1044: <p class="note">The state does not change. The event is dispatched
1045: for historical reasons.</p>
1046: </li>
1047:
1048: <li><p>Return the <code>send()</code> method call, but continue
1049: running the steps in this algorithm.</p></li>
1050:
1051: <li>
1052: <p>Make a request to <span>request URL</span>, using HTTP method
1053: <span>request method</span>, user <span>request username</span>
1054: (if non-null) and password <span>request password</span> (if
1.204 avankest 1055: non-null), taking into account the <span>request entity body</span>,
1056: list of <span>author request headers</span> and the rules listed at
1057: the end of this section.</p>
1.118 avankest 1058:
1.203 avankest 1059: <p>If there are cookies to be set, run these substeps:</p>
1.117 avankest 1060:
1.203 avankest 1061: <ol>
1062: <li><p>Wait until ownership of the <span>storage mutex</span> can
1063: be taken.</p></li>
1064:
1065: <li><p>Take ownership of the <span>storage mutex</span>.</p></li>
1066:
1067: <li><p>Update the cookies.
1068: [<cite><span>COOKIES</span></cite>]</p></li>
1069:
1070: <li><p>Release the <span>storage mutex</span> so that it is once
1071: again free.</p></li>
1072: </ol>
1073:
1074: <p>While processing the request
1075: <span title="queue a task">queue tasks</span>, as data becomes
1076: available and when the user interferes with the request, to follow
1077: the <span>request event rules</span> using the
1078: <span><code>XMLHttpRequest</code> networking task source</span> as
1079: <span>task source</span>.</p>
1080:
1081: <p>The <span>task</span> that is
1082: <span title="queue a task">queued</span> by the
1083: <span><code>XMLHttpRequest</code> networking task source</span> once
1084: the request is completed (i.e. no network errors or aborting of the
1085: algorithm occurred) is to <span>queue a task</span> to run these
1086: substeps rather than following the
1087: <span>request event rules</span>:</p>
1.121 avankest 1088:
1.203 avankest 1089: <ol>
1090: <li><p>Switch the state to <span title="DONE state">DONE</span>.</p></li>
1.58 avankest 1091:
1.203 avankest 1092: <li><p><span>Dispatch a <code>readystatechange</code> event</span>.</p></li>
1093: </ol>
1094:
1095: <p class="note">The <span>task</span> for these substeps is
1096: <span title="queue a task">queued</span> on the
1097: <span><code>XMLHttpRequest</code> event task source</span>.</p>
1098: </li>
1099: </ol>
1100: </dd>
1101: </dl>
1102: </li>
1103: </ol>
1.60 avankest 1104:
1.203 avankest 1105: <hr>
1106:
1107: <p>While executing the request certain events can influence the behavior
1108: of the <code>XMLHttpRequest</code> object. These are called the
1109: <dfn>request event rules</dfn>:</p>
1.118 avankest 1110:
1.203 avankest 1111: <dl class="switch">
1112: <dt>If the response is an HTTP redirect</dt>
1.118 avankest 1113:
1.203 avankest 1114: <dd>
1115: <p>If the redirect does not violate security (it is
1116: <span>same origin</span> for instance), infinite loop precautions, and
1117: the scheme is supported, transparently follow the redirect while
1118: observing the <span>request event rules</span>.</p>
1119:
1120: <p class="note">HTTP places requirements on the user agent regarding the
1.204 avankest 1121: preservation of the <span>request method</span> and
1122: <span>request entity body</span> during redirects, and also requires
1123: users to be notified of certain kinds of automatic redirections.</p>
1.118 avankest 1124:
1.203 avankest 1125: <!-- XXX HTTP needs fixing here -->
1.118 avankest 1126:
1.203 avankest 1127: <p>Otherwise, run these steps:</p>
1.121 avankest 1128:
1.203 avankest 1129: <ol>
1130: <li><p>Set the <span>response entity body</span> to null.</p></li>
1.60 avankest 1131:
1.203 avankest 1132: <li><p>Set the the <span>error flag</span> to true.</p></li>
1.121 avankest 1133:
1.203 avankest 1134: <li><p>Empty the list of <span>author request headers</span>.</p></li>
1.60 avankest 1135:
1.203 avankest 1136: <li><p>Switch the state to <span title="DONE state">DONE</span>.</p></li>
1.186 avankest 1137:
1.203 avankest 1138: <li><p>If the <span>asynchronous flag</span> is false raise a
1139: <code>NETWORK_ERR</code> exception and terminate the overall set of
1140: steps.</p></li>
1.118 avankest 1141:
1.203 avankest 1142: <li><p>If the <span>asynchronous flag</span> is true
1143: <span>queue a task</span> to
1144: <span>dispatch a <code>readystatechange</code> event</span>.</p></li>
1.118 avankest 1145:
1.203 avankest 1146: <li><p>Terminate the overall set of steps.</p></li>
1147: </ol>
1.118 avankest 1148:
1.203 avankest 1149: <p class="note">It is likely that a future version of this specification
1150: will dispatch an <code>error</code> event here as well.</p>
1151: </dd>
1.118 avankest 1152:
1.203 avankest 1153: <dt>If the user cancels the download</dt>
1154: <dd>
1155: <p>Run these steps:</p>
1.118 avankest 1156:
1.203 avankest 1157: <ol>
1158: <li><p>Set the <span>response entity body</span> to null.</p></li>
1.118 avankest 1159:
1.203 avankest 1160: <li><p>Set the the <span>error flag</span> to true.</p></li>
1.60 avankest 1161:
1.203 avankest 1162: <li><p>Empty the list of <span>author request headers</span>.</p></li>
1.118 avankest 1163:
1.203 avankest 1164: <li><p>Switch the state to <span title="DONE state">DONE</span>.</p></li>
1.153 avankest 1165:
1.203 avankest 1166: <li><p>If the <span>asynchronous flag</span> is false raise a
1167: <code>ABORT_ERR</code> exception and terminate the overall set of
1168: steps.</p></li>
1.118 avankest 1169:
1.203 avankest 1170: <li><p>If the <span>asynchronous flag</span> is true
1171: <span>queue a task</span> to
1172: <span>dispatch a <code>readystatechange</code> event</span>.</p></li>
1.153 avankest 1173:
1.203 avankest 1174: <li><p>Terminate the overall set of steps.</p></li>
1.58 avankest 1175: </ol>
1.14 avankest 1176:
1.203 avankest 1177: <p class="note">It is likely that a future version of this specification
1178: will dispatch an <code>abort</code> event here as well.</p>
1.8 avankest 1179: </dd>
1.12 avankest 1180:
1.203 avankest 1181: <dt>In case of network errors</dt>
1182: <dd>
1183: <p>In case of DNS errors, timeout, TLS negotiation failure, or other
1184: type of network errors, do not request user interaction and run these
1185: steps:</p>
1186:
1187: <p class="note">This does not include HTTP responses that indicate some
1188: type of error, such as HTTP status code 410.</p>
1.12 avankest 1189:
1.203 avankest 1190: <ol>
1191: <li><p>Set the <span>response entity body</span> to null.</p></li>
1192:
1193: <li><p>Set the the <span>error flag</span> to true.</p></li>
1194:
1195: <li><p>Empty the list of <span>author request headers</span>.</p></li>
1196:
1197: <li><p>Switch the state to <span title="DONE state">DONE</span>.</p></li>
1198:
1199: <li><p>If the <span>asynchronous flag</span> is false raise a
1200: <code>NETWORK_ERR</code> exception and terminate the overall set of
1201: steps.</p></li>
1202:
1203: <li><p>If the <span>asynchronous flag</span> is true
1204: <span>queue a task</span> to
1205: <span>dispatch a <code>readystatechange</code> event</span>.</p></li>
1206:
1207: <li><p>Terminate the overall set of steps.</p></li>
1208: </ol>
1209:
1210: <p class="note">It is likely that a future version of this
1211: specification will dispatch an <code>error</code> event here as
1212: well.</p>
1213: </dd>
1214:
1215: <dt>Once all HTTP headers have been received and the
1216: <span>asynchronous flag</span> is true</dt>
1.5 avankest 1217: <dd>
1.203 avankest 1218: <p>If all HTTP headers have been received, while receiving the message
1219: body (if any), run these steps:</p>
1220:
1221: <ol>
1222: <li><p>Switch the state to <span title="HEADERS_RECEIVED state">HEADERS_RECEIVED</span>.</p></li>
1223:
1224: <li><p><span>Queue a task</span> to
1225: <span>dispatch a <code>readystatechange</code> event</span>.</p></li>
1226: </ol>
1227: </dd>
1.60 avankest 1228:
1.203 avankest 1229: <dt>Once the first byte (or more) of the response entity body has been
1230: received and the <span>asynchronous flag</span> is true</dt>
1231: <dt>If there is no response entity body and the
1232: <span>asynchronous flag</span> is true</dt>
1233: <dd>
1.60 avankest 1234: <ol>
1.203 avankest 1235: <li><p>Switch the state to <span title="LOADING state">LOADING</span>.</p></li>
1236:
1237: <li><p><span>Queue a task</span> to
1238: <span>dispatch a <code>readystatechange</code> event</span>.</p></li>
1.60 avankest 1239: </ol>
1.5 avankest 1240: </dd>
1.203 avankest 1241: </dl>
1242:
1243: <hr>
1244:
1245: <p>If the user agent allows the user to configure a proxy it
1246: <em class="ct">should</em> modify the request appropriately;
1247: i.e. connect to the proxy host instead of the origin server, modify the
1248: <code>Request-Line</code> and
1249: send <code>Proxy-Authorization</code> headers as specified.</p>
1250:
1251: <p>If the user agent supports HTTP Authentication it
1252: <em class="ct">should</em> consider requests originating from this
1253: object to be part of the protection space that includes the accessed
1254: URIs and send <code>Authorization</code> headers and handle <code>401
1255: Unauthorized</code> requests appropriately. If authentication fails,
1256: and <var>stored user</var> and <var>stored password</var> are not
1257: provided, user agents <em class="ct">should</em> prompt the user for
1258: credentials. If authentication fails, and <var>stored user</var> and
1259: <var>stored password</var> are provided, user agents
1260: <em class="ct">must not</em> prompt the user for credentials.
1261: [<cite><span>RFC2617</span></cite>]</p>
1262:
1263: <p class="note">Users are not prompted if credentials are provided
1264: through the <code>open()</code> API so that authors can implement their
1265: own user interface.</p>
1266:
1267: <p>If the user agent supports HTTP State Management it
1268: <em class="ct">should</em> persist, discard and send cookies (as received
1269: in the <code>Set-Cookie</code> and <code>Set-Cookie2</code> response
1270: headers, and sent in the <code>Cookie</code> header) as applicable.
1271: [<cite><span>COOKIES</span></cite>]</p>
1272:
1273: <p>If the user agent implements a HTTP cache it <em class="ct">should</em>
1274: respect <code>Cache-Control</code> request headers set by
1275: <code>setRequestHeader()</code> (e.g., <code>Cache-Control: no-cache</code>
1276: bypasses the cache). It <em class="ct">must not</em> send
1277: <code>Cache-Control</code> or <code>Pragma</code> request headers
1278: automatically unless the user explicitly requests such behavior
1279: (e.g. by (force-)reloading the page).</p>
1280:
1281: <p>For <code>304 Not Modified</code> responses that are a result of a
1282: user agent generated conditional request the user agent
1283: <em class="ct">must</em> act as if the server gave a <code>200 OK</code>
1284: response with the appropriate content. The user agent
1285: <em class="ct">must</em> allow <code>setRequestHeader()</code> to
1286: override automatic cache validation by setting request headers (e.g.,
1287: <code>If-None-Match</code>, <code>If-Modified-Since</code>), in which
1288: case <code>304 Not Modified</code> responses <em class="ct">must</em> be
1289: passed through. [<cite><span>RFC2616</span></cite>]</p>
1290:
1291: <p>If the user agent implements server-driven content-negotiation
1292: it <em class="ct">should</em> set <code>Accept-Encoding</code> and
1293: <code>Accept-Charset</code> headers as appropriate.
1294: Unless set through <code>setRequestHeader()</code> user agents
1295: <em class="ct">should</em> set the <code>Accept</code> and
1296: <code>Accept-Language</code> headers as well. If <code>Accept</code> is
1297: set by the user agent it <em class="ct">must</em> have the value
1298: <code>*/*</code>. Responses <em class="ct">must</em> have the
1299: content-encodings automatically decoded.
1300: [<cite><span>RFC2616</span></cite>]</p>
1301:
1302: <p>Besides the <span>author request headers</span> user agents
1303: <em class="ct">should not</em> include additional request headers other
1304: than those mentioned above or other than those authors are not allowed
1305: to set using <code>setRequestHeader()</code>. This ensures that authors
1306: have a reasonably predictable API.</p>
1307:
1308:
1309: <h4>The <code title="">abort()</code> method</h4>
1310:
1311: <p>When the <dfn id="abort"><code>abort()</code></dfn> method is invoked,
1312: the user agent <em class="ct">must</em> run the following steps (unless
1313: otherwise noted):</p>
1.12 avankest 1314:
1.203 avankest 1315: <ol>
1316: <li><p><span title="abort send()">Abort the <code>send()</code> algorithm</span>.</p></li>
1317:
1318: <li><p>The user agent <em class="ct">should</em> cancel any network
1319: activity for which the object is responsible.</p></li>
1320:
1321: <li><p>Set the <span>response entity body</span> to null.</p></li>
1322:
1323: <li><p>Set the <span>error flag</span> to true.</p></li>
1324:
1325: <li><p>Empty the list of <span>author request headers</span>.</p></li>
1326:
1327: <li>
1328: <p>If the state is <span title="UNSENT state">UNSENT</span>,
1329: <span title="OPENED state">OPENED</span> with the
1330: <span><code>send()</code> flag</span> being false, or
1331: <span title="DONE state">DONE</span> go to the next step.</p>
1.12 avankest 1332:
1.203 avankest 1333: <p>Otherwise run these substeps:</p>
1.58 avankest 1334:
1335: <ol>
1.203 avankest 1336: <li><p>Switch the state to <span title="DONE state">DONE</span>.</p></li>
1.170 avankest 1337:
1.203 avankest 1338: <li><p>Set the <span><code>send()</code> flag</span> to false.</p></li>
1.96 avankest 1339:
1.203 avankest 1340: <li><p><span>Dispatch a <code>readystatechange</code> event</span>.</p></li>
1.58 avankest 1341: </ol>
1.203 avankest 1342: </li>
1343:
1344: <li>
1345: <p>Switch the state to <span title="UNSENT state">UNSENT</span>.</p>
1346:
1347: <p class="note">No <code>readystatechange</code> event is dispatched.</p>
1348:
1349: <p class="note">It is likely that a future version of this specification
1350: will dispatch an <code title="">abort</code> event here.</p>
1351: </li>
1352: </ol>
1353:
1354:
1355:
1.205 avankest 1356: <h3 id="response">Response</h3>
1.203 avankest 1357:
1358:
1359: <h4>The <code title="">status</code> attribute</h4>
1360:
1361: <p>The <dfn id="status"><code>status</code></dfn> attribute
1362: <em class="ct">must</em> return the HTTP status code sent by the server
1363: (typically <code>200</code> for a successful request). Otherwise, if not
1364: available, the user agent <em class="ct">must</em> raise an
1365: <code>INVALID_STATE_ERR</code> exception.</p>
1.24 avankest 1366:
1.203 avankest 1367: <!-- XXX define in terms of states -->
1368:
1369:
1370: <h4>The <code title="">statusText</code> attribute</h4>
1371:
1372: <p>The <dfn id="statustext"><code>statusText</code></dfn> attribute
1373: <em class="ct">must</em> return the HTTP status text sent by the server
1374: (appears after the status code). Otherwise, if not available (request is
1375: not initiated for instance), the user agent <em class="ct">must</em> raise
1376: an <code>INVALID_STATE_ERR</code> exception.</p>
1377:
1378: <!-- XXX define in terms of states -->
1379:
1380:
1381: <h4>The <code title="">getResponseHeader()</code> method</h4>
1382:
1383: <p>When the
1384: <dfn id="getresponseheader" title="getresponseheader"><code>getResponseHeader(<var>header</var>)</code></dfn>
1385: is invoked, the user agent <em class="ct">must</em> run the following
1386: steps:</p>
1387:
1388: <ol>
1389: <li><p>If the state is <span title="UNSENT state">UNSENT</span> or
1390: <span title="OPENED state">OPENED</span> raise an
1391: <code>INVALID_STATE_ERR</code> exception and terminate these
1392: steps.</p></li>
1393:
1394: <li><p>If <var>header</var> does not match the <code>field-name</code>
1395: production return <code>null</code> and terminate these steps.</p></li>
1396:
1397: <li><p>If the <span>error flag</span> is true return <code>null</code>
1398: and terminate these steps.</p></li>
1399:
1400: <li><p>If <var>header</var> is an <span>ASCII case-insensitive</span>
1401: match for <code>Set-Cookie</code> or <code>Set-Cookie2</code> return
1402: <code>null</code> and terminate these steps.</p></li>
1403:
1404: <li><p>If <var>header</var> is an <span>ASCII case-insensitive</span>
1405: match for multiple HTTP response headers, return the values of these
1406: headers as a single concatenated string separated from each other by a
1407: U+002C COMMA U+0020 SPACE character pair and terminate these
1408: steps.</p></li>
1409:
1410: <li><p>If <var>header</var> is an <span>ASCII case-insensitive</span>
1411: match for a single HTTP response header, return the value of that header
1412: and terminate these steps.</p></li>
1413:
1414: <li><p>Return <code>null</code>.</p></li>
1415: </ol>
1416:
1417: <div class="example">
1418: <pre><code>// The following script:
1.5 avankest 1419: var client = new XMLHttpRequest();
1.14 avankest 1420: client.open("GET", "test.txt", true);
1.5 avankest 1421: client.send();
1.12 avankest 1422: client.onreadystatechange = function() {
1.179 avankest 1423: if(this.readyState == 2) {
1.203 avankest 1424: print(client.getResponseHeader("Content-Type"));
1.12 avankest 1425: }
1426: }
1.5 avankest 1427:
1428: // ...should output something similar to the following text:
1.58 avankest 1429: Content-Type: text/plain; charset=utf-8</code></pre>
1.203 avankest 1430: </div>
1.12 avankest 1431:
1432:
1.203 avankest 1433: <h4>The <code title="">getAllResponseHeaders()</code> method</h4>
1.14 avankest 1434:
1.203 avankest 1435: <p>When the
1436: <dfn id="getallresponseheaders"><code>getAllResponseHeaders()</code></dfn>
1437: method is invoked, the user agent <em class="ct">must</em> run the
1438: following steps:</p>
1.58 avankest 1439:
1.203 avankest 1440: <ol>
1441: <li><p>If the state is <span title="UNSENT state">UNSENT</span> or
1442: <span title="OPENED state">OPENED</span> raise an
1443: <code>INVALID_STATE_ERR</code> exception and terminate these
1444: steps.</p></li>
1445:
1446: <li><p>If the <span>error flag</span> is true return the empty string and
1447: terminate these steps.</p></li>
1448:
1449: <li><p>Return all the HTTP headers, excluding headers that are an
1450: <span>ASCII case-insensitive</span> match for <code>Set-Cookie</code> or
1451: <code>Set-Cookie2</code>, as a single string, with each header line
1452: separated by a U+000D CR U+000A LF pair excluding the status line, and
1453: with each header name and header value separated by a
1454: U+003A COLON U+0020 SPACE pair.</p></li>
1455: </ol>
1.58 avankest 1456:
1.203 avankest 1457: <div class="example">
1458: <pre><code>// The following script:
1.1 avankest 1459: var client = new XMLHttpRequest();
1.14 avankest 1460: client.open("GET", "test.txt", true);
1.5 avankest 1461: client.send();
1.12 avankest 1462: client.onreadystatechange = function() {
1.179 avankest 1463: if(this.readyState == 2) {
1.203 avankest 1464: print(this.getAllResponseHeaders());
1.12 avankest 1465: }
1466: }
1.1 avankest 1467:
1.5 avankest 1468: // ...should output something similar to the following text:
1.203 avankest 1469: Date: 2004年10月24日 04:58:38 GMT
1470: Server: Apache/1.3.31 (Unix)
1471: Keep-Alive: timeout=15, max=99
1472: Connection: Keep-Alive
1473: Transfer-Encoding: chunked
1474: Content-Type: text/plain; charset=utf-8</code></pre>
1475: </div>
1476:
1477:
1478: <h4>Response Entity Body</h4>
1479:
1480: <p>The <dfn id="response-entity-body">response entity body</dfn> is the
1481: fragment of the <span>entity body</span> received so far
1482: (<span title="LOADING state">LOADING</span> state) or the complete
1483: <span>entity body</span> (<span title="DONE state">DONE</span> state). If
1484: there is no <span>entity body</span> the
1485: <span>response entity body</span> is null.</p>
1486:
1487: <hr>
1488:
1489: <p>The <dfn id="text-response-entity-body">text response entity body</dfn>
1490: is a <code>DOMString</code> representing the
1491: <span>response entity body</span>. The
1492: <span>text response entity body</span> is the return value of the
1493: following algorithm:</p>
1494:
1495: <ol>
1496: <li><p>If the <span>response entity body</span> is null return the empty
1497: string and terminate these steps.</p>
1498:
1499: <li><p>Let <var>charset</var> be null.</p></li>
1500:
1501: <li><p>If there is no <code>Content-Type</code> header or there is a
1502: <code>Content-Type</code> header which contains a MIME type that is
1503: <code>text/xml</code>, <code>application/xml</code> or ends in
1504: <code title="">+xml</code> (ignoring any parameters) use the rules set
1505: forth in the XML specifications to determine the character encoding. Let
1506: <var>charset</var> be the determined character encoding.
1507: [<cite><span>XML</span></cite>]</p></li>
1508:
1509: <li><p>If the <code>Content-Type</code> header contains a
1510: <code>text/html</code> MIME type follow the rules set forth in the
1511: HTML 5 specification to determine the character encoding. Let
1512: <var>charset</var> be the determined character encoding.
1513: [<cite><span>HTML5</span></cite>]</p></li>
1514:
1515: <li>
1516: <p>If the MIME type specified by the <code>Content-Type</code> header
1517: contains a <code>charset</code> parameter and <var>charset</var> is
1518: null let <var>charset</var> be the value of that parameter.</p>
1519:
1520: <p class="note">The algorithms described by the XML and HTML
1521: specifications already take <code>Content-Type</code> into account.</p>
1522: </li>
1523:
1524: <li>
1525: <!-- This stuff is copied from HTML5. Thanks Hixie! -->
1526: <p>If <var>charset</var> is null then, for each of the rows in the
1527: following table, starting with the first one and going down, if the first
1528: bytes of <var>bytes</var> match the bytes given in the first column, then
1529: let <var>charset</var> be the encoding given in the cell in the second
1530: column of that row. If there is no match <var>charset</var> remains
1531: null.</p>
1532:
1533: <table>
1534: <thead>
1535: <tr>
1536: <th>Bytes in Hexadecimal
1537: <th>Description
1538: <tbody><!-- UTF-32 is dead
1539: <tr>
1540: <td>00 00 FE FF
1541: <td>UTF-32BE BOM
1542: <tr>
1543: <td>FF FE 00 00
1544: <td>UTF-32LE BOM-->
1545: <tr>
1546: <td>FE FF
1547: <td>UTF-16BE BOM
1548: <tr>
1549: <td>FF FE
1550: <td>UTF-16LE BOM
1551: <tr>
1552: <td>EF BB BF
1553: <td>UTF-8 BOM<!-- nobody uses this
1554: <tr>
1555: <td>DD 73 66 73
1556: <td>UTF-EBCDIC
1557: -->
1558: </table>
1559: </li>
1560:
1561: <li><p>If <var>charset</var> is null let <var>charset</var> be
1562: UTF-8.</p></li>
1563:
1564: <li><p>Return the result of decoding the response entity body using
1565: <var>charset</var>. Replace bytes or sequences of bytes that are not
1566: valid according to the <var>charset</var> with a single U+FFFD
1567: REPLACEMENT CHARACTER character.</p></li>
1568: </ol>
1569:
1570: <p class="note">Authors are strongly encouraged to encode their resources
1571: using UTF-8.</p>
1572:
1573: <hr>
1574:
1575: <p>The <dfn id="xml-response-entity-body">XML response entity body</dfn>
1576: is either a <code>Document</code> representing the
1577: <span>response entity body</span> or <code>null</code>. The
1578: <span>XML response entity body</span> is the return value of the following
1579: algorithm:</p>
1.12 avankest 1580:
1.203 avankest 1581: <ol>
1582: <li><p>If the <span>response entity body</span> is null terminate these
1583: steps and return <code>null</code>.</p></li>
1.12 avankest 1584:
1.203 avankest 1585: <li><p>If a <code>Content-Type</code> is present and it does not contain
1586: a MIME type (ignoring any parameters) that is <code>text/xml</code>,
1587: <code>application/xml</code> or ends in <code title="">+xml</code> terminate
1588: these steps and return <code>null</code>. (Do not terminate these steps if
1589: there is no <code>Content-Type</code> header at all.)</p></li>
1590:
1591: <li>
1592: <p>Parse the <span>response entity body</span> into a document tree
1593: following the rules from the XML specifications. Let the result be
1594: <var>parsed document</var>. If this fails (unsupported character
1595: encoding, namespace well-formedness error, et cetera) terminate these
1596: steps return <code>null</code>. [<cite><span>XML</span></cite>]</p>
1597:
1598: <p class="note">Scripts in the resulting document tree will not be
1599: executed, resources referenced will not be loaded and no associated XSLT
1600: will be applied.</p>
1601: </li>
1.88 avankest 1602:
1.203 avankest 1603: <li><p>Return an object implementing the <code>Document</code>
1604: interface representing the <var>parsed document</var>.</p></li>
1605: </ol>
1.12 avankest 1606:
1607:
1.203 avankest 1608: <h4>The <code title="">responseText</code> attribute</h4>
1.12 avankest 1609:
1.203 avankest 1610: <p>The <dfn id="responsetext"><code>responseText</code></dfn> attribute
1611: <em class="ct">must</em> return the result of running the following
1612: steps:</p>
1.79 avankest 1613:
1.203 avankest 1614: <ol>
1615: <li><p>If the state is not <span title="LOADING state">LOADING</span>
1616: or <span title="DONE state">DONE</span> return the empty string and
1617: terminate these steps.</p></li>
1.75 avankest 1618:
1.203 avankest 1619: <li><p>Return the <span>text response entity body</span>.</p></li>
1620: </ol>
1.12 avankest 1621:
1622:
1.203 avankest 1623: <h4>The <code title="">responseXML</code> attribute</h4>
1.12 avankest 1624:
1.203 avankest 1625: <p>The <dfn id="responsexml"><code>responseXML</code></dfn> attribute
1626: <em class="ct">must</em> return the result of running the following
1627: steps:</p>
1.12 avankest 1628:
1.203 avankest 1629: <ol>
1630: <li><p>If the state is not <span title="DONE state">DONE</span> return
1631: <code>null</code> and terminate these steps.</p></li>
1.12 avankest 1632:
1.203 avankest 1633: <li><p>Return the <span>XML response entity body</span>.</p></li>
1634: </ol>
1.121 avankest 1635:
1.12 avankest 1636:
1.203 avankest 1637: <h3 id="exceptions">Exceptions</h3>
1.24 avankest 1638:
1.203 avankest 1639: <!-- XXX HTML5 assumes Web DOM Core will define these -->
1.32 avankest 1640:
1.138 avankest 1641: <p>Several algorithms in this specification may result in an exception
1642: being thrown. These exceptions are all part of the group
1.185 avankest 1643: <code>ExceptionCode</code> and use the <code>DOMException</code> object,
1.138 avankest 1644: which is defined in DOM Level 3 Core. In addition this specification
1645: extends the <code>ExceptionCode</code> group with several new
1646: constants as indicated below. [<cite><span>DOM3Core</span></cite>]</p>
1.203 avankest 1647:
1.193 avankest 1648: <p class="note">Thus, exceptions used by this specification and not
1649: defined in this section are defined by DOM Level 3 Core.</p>
1.31 avankest 1650:
1.138 avankest 1651: <pre class="idl">const unsigned short <span>SECURITY_ERR</span> = 18;
1.199 avankest 1652: const unsigned short <span>NETWORK_ERR</span> = 19;
1653: const unsigned short <span>ABORT_ERR</span> = 20;</pre>
1.31 avankest 1654:
1.138 avankest 1655: <p>The <dfn id="security-err"><code>SECURITY_ERR</code></dfn> exception is
1656: raised if an attempt is made to perform an operation or access some data
1657: in a way that would be a security risk or a violation of the user agent's
1658: security policy.</p>
1659:
1660: <!-- http://lists.w3.org/Archives/Public/public-webapi/2006May/0027.html -->
1661:
1.33 avankest 1662: <p>The <dfn id="network-err"><code>NETWORK_ERR</code></dfn> exception is
1.138 avankest 1663: raised when a network error occurs in synchronous requests.</p>
1.121 avankest 1664:
1.138 avankest 1665: <p>The <dfn id="abort-err"><code>ABORT_ERR</code></dfn> exception is
1666: raised when the user aborts a request in synchronous requests.</p>
1.203 avankest 1667:
1.199 avankest 1668: <p class="note">These exceptions might be folded into an update of
1669: DOM Level 3 Core in due course, as they are appropriate for other API
1670: specifications as well.</p>
1.121 avankest 1671:
1672:
1.203 avankest 1673:
1.29 avankest 1674: <h2 class="no-num" id="notcovered">Not in this Specification</h2>
1675:
1.143 avankest 1676: <p><em>This section is non-normative.</em></p>
1.29 avankest 1677:
1.72 avankest 1678: <p>This specification does not include the following features which are
1679: being considered for a future version of this specification:</p>
1.29 avankest 1680:
1681: <ul>
1682: <li><code>load</code> event and <code>onload</code> attribute;</li>
1683: <li><code>error</code> event and <code>onerror</code> attribute;</li>
1684: <li><code>progress</code> event and <code>onprogress</code> attribute;</li>
1685: <li><code title="">abort</code> event and <code>onabort</code> attribute;</li>
1686: <li>Timers have been suggested, perhaps an <code>ontimeout</code>
1687: attribute;</li>
1688: <li>Property to disable following redirects;</li>
1.30 avankest 1689: <li><code title="">responseXML</code> for <code>text/html</code>
1690: documents;</li>
1.203 avankest 1691: <li>Cross-origin <code title="">XMLHttpRequest</code>;</li>
1.87 avankest 1692: <li><code>responseBody</code> to deal with byte streams;</li>
1.114 avankest 1693: <li><code>overrideMimeType</code> to fix up MIME types;</li>
1.87 avankest 1694: <li><code>getRequestHeader()</code> and
1695: <code>removeRequestHeader()</code>.</li>
1.29 avankest 1696: </ul>
1697:
1.203 avankest 1698:
1699:
1.1 avankest 1700: <h2 class="no-num" id="bibref">References</h2>
1.203 avankest 1701:
1.177 avankest 1702: <p>Unless marked "Non-normative" these references are normative.</p>
1.11 avankest 1703:
1.6 avankest 1704: <dl>
1.203 avankest 1705: <dt>[<dfn id="ref-cookies=">COOKIES</dfn>]</dt>
1706: <dd><cite><a href="http://ietf.org/rfc/rfc2109">HTTP State Management
1707: Mechanism</a></cite>, D. Kristol, L. Montulli, editors. IETF, February
1708: 1997.</dd>
1709: <dd><cite><a href="http://ietf.org/rfc/rfc2965">HTTP State Management
1710: Mechanism</a></cite>, D. Kristol, L. Montulli, editors. IETF, October
1711: 2000.</dd>
1712:
1713: <!-- XXX These specs do not match reality. Also, the latter obsoletes the
1714: former -->
1715:
1.155 avankest 1716: <dt>[<dfn id="ref-dom2events">DOM2Events</dfn>]</dt>
1717: <dd><cite><a href="http://www.w3.org/TR/DOM-Level-2-Events/">Document
1.160 avankest 1718: Object Model (DOM) Level 2 Events Specification</a></cite>, T. Pixley,
1719: editor. W3C, November 2000.</dd>
1.155 avankest 1720:
1.145 avankest 1721: <dt>[<dfn id="ref-dom3core">DOM3Core</dfn>]</dt>
1.11 avankest 1722: <dd><cite><a href="http://www.w3.org/TR/DOM-Level-3-Core">Document Object
1.92 avankest 1723: Model (DOM) Level 3 Core Specification</a></cite>, A. Le Hors, P. Le
1.139 avankest 1724: Hégaret, L. Wood, G. Nicol, J. Robie, M. Champion, S. Byrne,
1725: editors. W3C, April 2004.</dd>
1.11 avankest 1726:
1.117 avankest 1727: <dt>[<dfn id="ref-ecmascript">ECMAScript</dfn>]</dt>
1.92 avankest 1728: <dd><cite><a href="http://www.ecma-international.org/publications/standards/Ecma-262.htm">ECMAScript
1729: Language Specification</a></cite>, Third Edition. ECMA, December 1999.</dd>
1.171 avankest 1730:
1.145 avankest 1731: <dt>[<dfn id="ref-html5">HTML5</dfn>]</dt>
1.171 avankest 1732: <dd><cite><a href="http://www.w3.org/html/wg/html5/">HTML 5</a></cite>
1733: (work in progress), I. Hickson, D. Hyatt, editors. W3C, 2008.</dd>
1.142 avankest 1734: <dd><cite><a href="http://www.whatwg.org/specs/web-apps/current-work/">HTML 5</a></cite>
1.171 avankest 1735: (work in progress), I. Hickson, editor. WHATWG, 2008.</dd>
1.198 avankest 1736:
1737: <dt>[<dfn id="ref-httpverbsec">HTTPVERBSEC</dfn>]</dt>
1738: <dd>(Non-normative) <cite><a href="http://www.kb.cert.org/vuls/id/867593">Multiple
1739: vendors' web servers enable HTTP TRACE method by default</a></cite>,
1740: US-CERT.</dd>
1741: <dd>(Non-normative) <cite><a href="http://www.kb.cert.org/vuls/id/288308">Microsoft
1742: Internet Information Server (IIS) vulnerable to cross-site scripting via
1743: HTTP TRACK method</a></cite>, US-CERT.</dd>
1744: <dd>(Non-normative) <cite><a href="http://www.kb.cert.org/vuls/id/150227">HTTP
1745: proxy default configurations allow arbitrary TCP connections</a></cite>,
1746: US-CERT.</dd>
1747:
1.145 avankest 1748: <dt>[<dfn id="ref-rfc2119">RFC2119</dfn>]</dt>
1.117 avankest 1749: <dd><cite><a href="http://ietf.org/rfc/rfc2119">Key words for use in RFCs to
1750: Indicate Requirement Levels</a></cite>, S. Bradner. IETF, March 1997.</dd>
1.12 avankest 1751:
1.145 avankest 1752: <dt>[<dfn id="ref-rfc2616">RFC2616</dfn>]</dt>
1.11 avankest 1753: <dd><cite><a href="http://ietf.org/rfc/rfc2616">Hypertext Transfer Protocol
1.92 avankest 1754: -- HTTP/1.1</a></cite>, R. Fielding, J. Gettys, J. Mogul, H. Frystyk, L.
1755: Masinter, P. Leach, T. Berners-Lee, editors. IETF, June 1999.</dd>
1.12 avankest 1756:
1.37 avankest 1757: <dt>[<dfn id="ref-rfc2617">RFC2617</dfn>]</dt>
1.11 avankest 1758: <dd><cite><a href="http://ietf.org/rfc/rfc2617">HTTP Authentication: Basic
1.92 avankest 1759: and Digest Access Authentication</a></cite>, P. Hallam-Baker, J.
1760: Hostetler, S. Lawrence, P. Leach, A. Luotonen, L. Stewart, editors. IETF,
1761: June 1999.</dd>
1.12 avankest 1762:
1.37 avankest 1763: <dt>[<dfn id="ref-rfc3986">RFC3986</dfn>]</dt>
1.11 avankest 1764: <dd><cite><a href="http://ietf.org/rfc/rfc3986">Uniform Resource Identifier
1.92 avankest 1765: (URI): Generic Syntax</a></cite>, T. Berners-Lee, R. Fielding, L. Masinter,
1766: editors. IETF, January 2005.</dd>
1.184 avankest 1767:
1.203 avankest 1768: <dt>[<dfn id="ref-webidl">WebIDL</dfn>]</dt>
1.200 avankest 1769: <dd><cite><a href="http://dev.w3.org/2006/webapi/WebIDL/">Web
1.203 avankest 1770: IDL</a></cite> (work in progress), C. McCormack, editor. W3C, 2009.</dd>
1.181 avankest 1771:
1.92 avankest 1772: <dt>[<dfn id="ref-xml">XML</dfn>]</dt>
1773: <dd><cite><a href="http://www.w3.org/TR/xml/">Extensible Markup Language
1.203 avankest 1774: (XML) 1.0 (Fifth Edition)</a></cite>, T. Bray, J. Paoli, C.
1775: Sperberg-McQueen, E. Maler, F. Yergeau, editors. W3C, November 2008.</dd>
1.92 avankest 1776: <dd><cite><a href="http://www.w3.org/TR/xml-names/">Namespaces in XML
1.117 avankest 1777: (Second Edition)</a></cite>, T. Bray, D. Hollander, A. Layman, R. Tobin,
1778: editors. W3C, August 2006.</dd>
1.1 avankest 1779: </dl>
1.11 avankest 1780:
1.203 avankest 1781:
1782:
1.130 avankest 1783: <h2 class="no-num" id="acknowledgments">Acknowledgments</h2>
1.11 avankest 1784:
1.159 avankest 1785: <p>The editor would like to thank
1.12 avankest 1786:
1.163 avankest 1787: Addison Phillips,
1.159 avankest 1788: Ahmed Kamel,
1789: Alex Hopmann,
1790: Alex Vincent,
1791: Alexey Proskuryakov,
1792: Asbjørn Ulsberg,
1793: Boris Zbarsky,
1794: Björn Höhrmann,
1795: Cameron McCormack,
1796: Christophe Jolif,
1797: Charles McCathieNevile,
1798: Dan Winship,
1799: David Håsäther,
1800: Dean Jackson,
1801: Denis Sureau,
1802: Doug Schepers,
1803: Douglas Livingstone,
1804: Elliotte Harold,
1805: Eric Lawrence,
1.196 avankest 1806: Erik Dahlström,
1.163 avankest 1807: Geoffrey Sneddon,
1.159 avankest 1808: Gideon Cohn,
1809: Gorm Haug Eriksen,
1810: Hallvord R. M. Steen,
1811: Håkon Wium Lie,
1812: Ian Davis,
1813: Ian Hickson,
1814: Ivan Herman,
1815: Jeff Walden,
1816: Jens Lindström,
1817: Jim Deegan,
1818: Jim Ley,
1819: Joe Farro,
1820: Jonas Sicking,
1821: Julian Reschke,
1822: Karl Dubost,
1.175 avankest 1823: Lachlan Hunt,
1.159 avankest 1824: Maciej Stachowiak,
1825: Magnus Kristiansen,
1826: Marc Hadley,
1827: Marcos Caceres,
1828: Mark Baker,
1.203 avankest 1829: Mark Birbeck,
1.159 avankest 1830: Mark Nottingham,
1831: Mohamed Zergaoui,
1832: Pawel Glowacki,
1833: Robin Berjon,
1834: Ruud Steltenpool,
1835: Simon Pieters,
1836: Stewart Brodie,
1837: Sunava Dutta,
1.186 avankest 1838: Thomas Roessler,
1.203 avankest 1839: Tom Magliery, and
1.159 avankest 1840: Zhenbin Xu
1.181 avankest 1841:
1.159 avankest 1842: for their contributions to this specification.</p>
1.12 avankest 1843:
1.1 avankest 1844: <p>Special thanks to the Microsoft employees who first implemented the
1.143 avankest 1845: <code title="">XMLHttpRequest</code> interface, which was first widely
1846: deployed by the Windows Internet Explorer browser.</p>
1.12 avankest 1847:
1.143 avankest 1848: <p>Special thanks also to the WHATWG for drafting an initial version of
1849: this specification in their Web Applications 1.0 document (now renamed to
1850: HTML 5). [<cite><span>HTML5</span></cite>]</p>
1.12 avankest 1851:
1.143 avankest 1852: <p>Thanks also to all those who have helped to improve this specification
1853: by sending suggestions and corrections. (Please, keep bugging us with your
1.22 avankest 1854: issues!)</p>
1.1 avankest 1855: </body>
1856: </html>
Webmaster