Annotation of 2006/webapi/XMLHttpRequest/Overview.src.html, revision 1.353
1.248 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 }
1.248 avankest 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.269 avankest 17: dl.domintro { color: green; margin: 2em 0 2em 2em; padding: 0.5em 1em; border: none; background: #DDFFDD; }
18: dl.domintro dt, dl.domintro dt * { color: black; text-decoration: none; }
19: dl.domintro dd { margin: 0.5em 0 1em 2em; padding: 0; }
20: dl.domintro dd p { margin: 0.5em 0; }
21: dl.domintro:before { display: table; margin: -1em -0.5em -0.5em auto; width: auto; content: 'This box is non-normative. Implementation requirements are given below this box.'; color: red; border: solid 2px; background: white; padding: 0 0.25em; }
1.16 avankest 22: em.ct { text-transform:lowercase; font-variant:small-caps; font-style:normal }
23: dfn { font-weight:bold; font-style:normal }
24: code { color:orangered }
25: code :link, code :visited { color:inherit }
1.203 avankest 26: hr:not(.top) { display:block; background:none; border:none; padding:0; margin:2em 0; height:auto }
27: table { border-collapse:collapse; border-style:hidden hidden none hidden }
28: table thead { border-bottom:solid }
29: table tbody th:first-child { border-left:solid }
30: table td, table th { border-left:solid; border-right:solid; border-bottom:solid thin; vertical-align:top; padding:0.2em }
1.16 avankest 31: </style>
1.147 avankest 32: <link rel="stylesheet" href="http://www.w3.org/StyleSheets/TR/W3C-[STATUS]">
1.1 avankest 33: </head>
34: <body>
35: <div class="head">
1.330 avankest 36: <!--logo-->
1.12 avankest 37:
1.229 avankest 38: <h1 class="head" id="the-xmlhttprequest-object">XMLHttpRequest</h1>
1.248 avankest 39:
1.12 avankest 40:
1.149 avankest 41: <h2 class="no-num no-toc" id="w3c-doctype">[LONGSTATUS] [DATE: 3 August 2002]</h2>
1.12 avankest 42:
1.1 avankest 43: <dl>
1.10 avankest 44: <dt>This Version:</dt>
1.330 avankest 45: <dd class=dontpublish><a href="http://dev.w3.org/2006/webapi/XMLHttpRequest/">http://dev.w3.org/2006/webapi/XMLHttpRequest/</a></dd>
46: <dd class=publish><a href="[VERSION]">[VERSION]</a></dd>
1.14 avankest 47:
1.330 avankest 48: <dt class=publish>Latest Version:</dt>
49: <dd class=publish><a href="[LATEST]">[LATEST]</a></dd>
1.203 avankest 50:
1.333 avankest 51: <dt class=publish>Latest Editor Draft:</dt>
1.330 avankest 52: <dd class=publish><a href="http://dev.w3.org/2006/webapi/XMLHttpRequest/">http://dev.w3.org/2006/webapi/XMLHttpRequest/</a></dd>
1.14 avankest 53:
1.10 avankest 54: <dt>Previous Versions:</dt>
1.248 avankest 55:
1.291 avankest 56: <dd><a href="http://www.w3.org/TR/2010/CR-XMLHttpRequest-20100803/">http://www.w3.org/TR/2010/CR-XMLHttpRequest-20100803/</a></dd>
1.288 avankest 57: <dd><a href="http://www.w3.org/TR/2009/WD-XMLHttpRequest-20091119/">http://www.w3.org/TR/2009/WD-XMLHttpRequest-20091119/</a></dd>
1.231 avankest 58: <dd><a href="http://www.w3.org/TR/2009/WD-XMLHttpRequest-20090820/">http://www.w3.org/TR/2009/WD-XMLHttpRequest-20090820/</a></dd>
1.173 avankest 59: <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 60: <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 61: <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 62: <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 63: <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 64: <dd><a href="http://www.w3.org/TR/2006/WD-XMLHttpRequest-20060619/">http://www.w3.org/TR/2006/WD-XMLHttpRequest-20060619/</a></dd>
65: <dd><a href="http://www.w3.org/TR/2006/WD-XMLHttpRequest-20060405/">http://www.w3.org/TR/2006/WD-XMLHttpRequest-20060405/</a></dd>
1.248 avankest 66:
67:
1.14 avankest 68:
1.1 avankest 69: <dt>Editor:</dt>
70: <dd><a href="http://annevankesteren.nl/">Anne van Kesteren</a>
71: (<a href="http://www.opera.com/">Opera Software ASA</a>)
72: <<a href="mailto:annevk@opera.com">annevk@opera.com</a>></dd>
73: </dl>
1.14 avankest 74:
1.353 ! avankest 75: <p class=dontpublish><a rel=license href="http://creativecommons.org/publicdomain/zero/1.0/"><img src="http://i.creativecommons.org/p/zero/1.0/80x15.png" alt=CC0></a>
! 76: To the extent possible under law, the editor has waived all copyright and
! 77: related or neighboring rights to this work. In addition, as of
! 78: [DATE: 01 Jan 1901], the editor has made this specification available
! 79: under the
! 80: <a rel=license
! 81: href="http://www.openwebfoundation.org/legal/the-owf-1-0-agreements/owfa-1-0">Open Web Foundation Agreement Version 1.0</a>,
! 82: which is available at
! 83: http://www.openwebfoundation.org/legal/the-owf-1-0-agreements/owfa-1-0.
! 84: <div class=publish><!--copyright--></div>
! 85:
1.1 avankest 86: </div>
1.12 avankest 87:
1.1 avankest 88: <hr>
1.12 avankest 89:
1.1 avankest 90: <h2 class="no-num no-toc" id="specabstract">Abstract</h2>
1.10 avankest 91:
1.248 avankest 92:
93:
1.229 avankest 94: <p>The XMLHttpRequest specification defines an API
1.207 avankest 95: that provides scripted client functionality for transferring data between
96: a client and a server.</p>
1.248 avankest 97:
1.12 avankest 98:
1.1 avankest 99: <h2 class="no-num no-toc" id="sotd">Status of this Document</h2>
1.12 avankest 100:
1.1 avankest 101: <p><em>This section describes the status of this document at the time of its
1.36 avankest 102: publication. Other documents may supersede this document. A list of current
103: W3C publications and the latest revision of this technical report can be
104: found in the <a href="http://www.w3.org/TR/">W3C technical reports index</a>
1.117 avankest 105: at http://www.w3.org/TR/.</em></p>
1.36 avankest 106:
1.330 avankest 107: <p>This is the [DATE: 3 August 2002] [LONGSTATUS] of
1.248 avankest 108: XMLHttpRequest. Please send comments to
109: <a href="mailto:public-webapps@w3.org?subject=[XHR]%20">public-webapps@w3.org</a>
1.207 avankest 110: (<a href="http://lists.w3.org/Archives/Public/public-webapps/">archived</a>)
1.248 avankest 111: with <samp>[XHR]</samp> at the start of the subject line.</p>
1.295 avankest 112:
1.287 avankest 113:
114: <p>For the last Last Call Working Draft the Working Group has kept a
115: <a href="http://dev.w3.org/2006/webapi/XMLHttpRequest/disposition-of-comments-3">disposition of comments</a>
1.290 avankest 116: document. A
117: <a href="http://dev.w3.org/cvsweb/2006/webapi/XMLHttpRequest/Overview.src.html">list of changes</a>
118: is available via a Web view of CVS. (Due to the way the document is edited
119: certain commit messages have introduced negligible changes to this
120: document and are in fact only relevant for XMLHttpRequest Level 2.)</p>
1.291 avankest 121:
1.51 avankest 122:
1.47 avankest 123: <p>This document is produced by the
1.248 avankest 124: <a href="http://www.w3.org/2008/webapps/">Web Applications</a> (WebApps) Working Group.
125: The WebApps Working Group is part of the
1.207 avankest 126: <a href="http://www.w3.org/2006/rwc/Activity">Rich Web Clients Activity</a>
1.248 avankest 127: in the W3C <a href="http://www.w3.org/Interaction/">Interaction Domain</a>.</p>
1.12 avankest 128:
1.1 avankest 129: <p>This document was produced by a group operating under the
1.248 avankest 130: <a href="http://www.w3.org/Consortium/Patent-Policy-20040205/">5 February 2004
131: W3C Patent Policy</a>. W3C maintains a
1.207 avankest 132: <a rel="disclosure" href="http://www.w3.org/2004/01/pp-impl/42538/status">public
1.248 avankest 133: list of any patent disclosures</a> made in connection with the deliverables of
134: the group; that page also includes instructions for disclosing a patent. An
135: individual who has actual knowledge of a patent which the individual believes
136: contains
1.36 avankest 137: <a href="http://www.w3.org/Consortium/Patent-Policy-20040205/#def-essential">Essential
138: Claim(s)</a> must disclose the information in accordance with
139: <a href="http://www.w3.org/Consortium/Patent-Policy-20040205/#sec-Disclosure">section
140: 6 of the W3C Patent Policy</a>.</p>
1.12 avankest 141:
1.291 avankest 142: <p>Publication as a Working Draft does not imply endorsement by the W3C
1.248 avankest 143: Membership. This is a draft document and may be updated, replaced or
144: obsoleted by other documents at any time. It is inappropriate to cite this
145: document as other than work in progress.</p>
1.295 avankest 146:
1.307 avankest 147:
1.268 avankest 148: <h3 class="no-num no-toc" id="crec">Candidate Recommendation Exit Criteria</h3>
149:
150: <p>To exit the Candidate Recommendation (CR) stage the following criteria
1.330 avankest 151: must have been met:</p>
1.268 avankest 152:
153: <ol>
154: <li>There will be at least two interoperable implementations passing all
1.286 avankest 155: test cases in the
156: <a href="http://test.w3.org/webapps/tests/XMLHttpRequest/info.htm">test suite</a>
157: for this specification. An implementation is to be available (i.e. for
158: download), shipping (i.e. not private), and not experimental (i.e.
159: intended for a wide audience). The working group will decide when the
1.290 avankest 160: test suite is of sufficient quality to test interoperability and will
161: produce implementation reports (hosted together with the test suite).</li>
1.268 avankest 162:
1.291 avankest 163: <li>A minimum of six months of the CR stage will have elapsed. This is to
1.268 avankest 164: ensure that enough time is given for any remaining major errors to be
165: caught. The CR period will be extended if implementations are slow to
1.291 avankest 166: appear.</li> <!-- XXX need to add date -->
1.282 avankest 167:
1.283 avankest 168: <li>Text, which can be in a separate document, exists that explains the
169: security considerations for this specification. This may be done in a
170: generic manner as they are most likely applicable to various APIs. The
171: working group will decide whether the text is of sufficient quality.</li>
1.268 avankest 172: </ol>
1.307 avankest 173:
1.207 avankest 174:
175:
1.1 avankest 176: <h2 class="no-num no-toc" id="toc">Table of Contents</h2>
1.21 avankest 177:
1.1 avankest 178: <!--toc-->
1.12 avankest 179:
1.207 avankest 180:
181:
1.1 avankest 182: <h2 id="introduction">Introduction</h2>
1.12 avankest 183:
1.1 avankest 184: <p><em>This section is non-normative.</em></p>
1.12 avankest 185:
1.183 avankest 186: <p>The <code>XMLHttpRequest</code> object implements an interface exposed
187: by a scripting engine that allows scripts to perform HTTP client
188: functionality, such as submitting form data or loading data from a
1.330 avankest 189: server. It is the ECMAScript HTTP API.
190: <span data-anolis-ref class=informative>ECMASCRIPT</span>
1.24 avankest 191:
1.1 avankest 192: <p>The name of the object is <code>XMLHttpRequest</code> for compatibility
1.183 avankest 193: with the Web, though each component of this name is potentially
194: misleading. First, the object supports any text based format, including
195: XML. Second, it can be used to make requests over both HTTP and HTTPS
196: (some implementations support protocols in addition to HTTP and HTTPS, but
197: that functionality is not covered by this specification). Finally, it
198: supports "requests" in a broad sense of the term as it pertains to HTTP;
199: namely all activity involved with HTTP requests or responses for the
200: defined HTTP methods.</p>
1.12 avankest 201:
1.14 avankest 202: <div class="example">
1.250 avankest 203: <p>Some simple code to do something with data from an XML document
204: fetched over the network:</p>
1.16 avankest 205:
1.308 avankest 206: <pre><code>function processData(data) {
1.312 avankest 207: // taking care of data
1.14 avankest 208: }
209:
210: function handler() {
1.312 avankest 211: if(this.readyState == this.DONE) {
212: if(this.status == 200 &&
213: this.responseXML != null &&
214: this.responseXML.getElementById('test').textContent) {
1.308 avankest 215: // success!
216: processData(this.responseXML.getElementById('test').textContent);
217: return;
218: }
1.312 avankest 219: // something went wrong
220: processData(null);
1.308 avankest 221: }
1.14 avankest 222: }
1.12 avankest 223:
1.14 avankest 224: var client = new XMLHttpRequest();
225: client.onreadystatechange = handler;
1.250 avankest 226: client.open("GET", "unicorn.xml");
1.58 avankest 227: client.send();</code></pre>
1.16 avankest 228:
1.56 avankest 229: <p>If you just want to log a message to the server:</p>
1.16 avankest 230:
1.58 avankest 231: <pre><code>function log(message) {
1.308 avankest 232: var client = new XMLHttpRequest();
233: client.open("POST", "/log");
234: client.setRequestHeader("Content-Type", "text/plain;charset=UTF-8");
235: client.send(message);
1.58 avankest 236: }</code></pre>
1.16 avankest 237:
1.14 avankest 238: <p>Or if you want to check the status of a document on the server:</p>
1.16 avankest 239:
1.58 avankest 240: <pre><code>function fetchStatus(address) {
1.308 avankest 241: var client = new XMLHttpRequest();
242: client.onreadystatechange = function() {
243: // in case of network errors this might not give reliable results
1.310 avankest 244: if(this.readyState == this.DONE)
1.308 avankest 245: returnStatus(this.status);
246: }
247: client.open("HEAD", address);
248: client.send();
1.58 avankest 249: }</code></pre>
1.14 avankest 250: </div>
1.12 avankest 251:
1.203 avankest 252:
253:
1.248 avankest 254:
1.324 avankest 255: <h2 id="conformance">Conformance</h2>
1.12 avankest 256:
1.27 avankest 257: <p>Everything in this specification is normative except for diagrams,
258: examples, notes and sections marked non-normative.</p>
1.12 avankest 259:
1.330 avankest 260: <p>The key words must, must not, should, should not and may in this
261: document are to be interpreted as described in RFC 2119.
262: <span data-anolis-ref>RFC2119</span></p>
1.12 avankest 263:
1.299 avankest 264: <p>This specification defines a single conformance class:</p>
1.12 avankest 265:
1.1 avankest 266: <dl>
1.74 avankest 267: <dt><dfn id="conforming-user-agent">Conforming user agent</dfn></dt>
1.24 avankest 268:
1.74 avankest 269: <dd>
1.330 avankest 270: <p>A user agent must behave as described in this
1.106 avankest 271: specification in order to be considered conformant.</p>
1.95 avankest 272:
1.330 avankest 273: <p>User agents may implement algorithms given in
1.140 avankest 274: this specification in any way desired, so long as the end result is
275: indistinguishable from the result that would be obtained by the
276: specification's algorithms.</p>
1.110 avankest 277:
1.95 avankest 278: <p class="note">This specification uses both the terms "conforming user
279: agent(s)" and "user agent(s)" to refer to this product class.</p>
1.74 avankest 280: </dd>
1.1 avankest 281: </dl>
1.32 avankest 282:
1.153 avankest 283: <h3 id="dependencies">Dependencies</h3>
1.33 avankest 284:
1.29 avankest 285: <p>This specification relies on several underlying specifications.</p>
1.248 avankest 286:
1.29 avankest 287: <dl>
1.248 avankest 288:
289:
1.342 avankest 290: <dt>DOM4</dt>
1.330 avankest 291: <dd><p>A <span>conforming user agent</span> must
1.342 avankest 292: support at least the subset of the functionality defined in DOM4 that
1.323 avankest 293: this specification relies upon, such as various exceptions and
1.342 avankest 294: <code data-anolis-spec=dom>EventTarget</code>. <span data-anolis-ref>DOM</span></p></dd>
1.29 avankest 295:
1.330 avankest 296: <dt>File API</dt>
297: <dd><p>A <span>conforming user agent</span> must
298: support at least the subset of the functionality defined in File API that
299: this specification relies upon, such as the <code data-anolis-spec=fileapi>Blob</code> and
300: <code data-anolis-spec=fileapi>File</code> interfaces. <span data-anolis-ref>FILEAPI</span></p>
1.310 avankest 301:
302:
1.322 avankest 303: <dt>HTML</dt>
1.330 avankest 304: <dd><p>A <span>conforming user agent</span> must
305: support at least the subset of the functionality defined in HTML that
306: this specification relies upon, such as the basics of the
1.342 avankest 307: <code data-anolis-spec=html>Window</code> object and serializing a <code data-anolis-spec=dom>Document</code>
1.330 avankest 308: object. <span data-anolis-ref>HTML</span>
1.161 avankest 309:
1.29 avankest 310: <dt>HTTP</dt>
1.330 avankest 311: <dd><p>A <span>conforming user agent</span> must
1.299 avankest 312: support some version of the HTTP protocol. Requirements regarding HTTP
1.330 avankest 313: are made throughout the specification. <span data-anolis-ref>HTTP</span>
314:
315:
1.189 avankest 316:
1.181 avankest 317: <dt>Web IDL</dt>
1.330 avankest 318: <dd><p>A <span>conforming user agent</span> must also
1.248 avankest 319: be a conforming implementation of the IDL fragments in this
320: specification, as described in the Web IDL specification.
1.330 avankest 321: <span data-anolis-ref>WEBIDL</span>
1.248 avankest 322:
1.299 avankest 323: <dt>XML</dt>
1.330 avankest 324: <dd><p>A <span>conforming user agent</span> must be a
1.299 avankest 325: conforming XML processor that reports violations of namespace
1.330 avankest 326: well-formedness. <span data-anolis-ref>XML</span>
327: <span data-anolis-ref>XMLNS</span>
1.29 avankest 328: </dl>
1.12 avankest 329:
1.157 avankest 330:
1.324 avankest 331: <h3 id="extensibility">Extensibility</h3>
332:
333: <p>User agents, Working Groups, and other interested parties are
334: <em>strongly encouraged</em> to discuss extensions on a relevant public
335: forum, preferably
336: <a href="mailto:public-webapps@w3.org">public-webapps@w3.org</a>. If this
337: is for some reason not possible prefix the extension in some way and start
338: the prefix with an uppercase letter. E.g. if company Foo wants to add a
339: private method <code>bar()</code> it could be named <code>FooBar()</code>
340: to prevent clashes with a potential future standardized
341: <code>bar()</code>.</p>
342:
343:
344:
345: <h2 id="terminology">Terminology</h2>
1.209 avankest 346:
1.248 avankest 347:
1.292 avankest 348:
1.258 avankest 349: <p>To <dfn>deflate a DOMString into a byte sequence</dfn> means to create
1.330 avankest 350: a sequence of bytes such that the <var title>n</var>th byte of the
351: sequence is equal to the low-order byte of the <var title>n</var>th
1.258 avankest 352: code point in the original DOMString.</p>
353:
354: <p>To <dfn>inflate a byte sequence into a DOMString</dfn> means to create
1.330 avankest 355: a DOMString such that the <var title>n</var>th code point has 0x00 as
356: the high-order byte and the <var title>n</var>th byte of the byte
1.258 avankest 357: sequence as the low-order byte.</p>
1.256 avankest 358:
1.203 avankest 359:
1.248 avankest 360:
1.334 avankest 361: <h2>Interface <code title>XMLHttpRequest</code></h2>
1.12 avankest 362:
1.320 avankest 363: <p>The <code>XMLHttpRequest</code> object can be used by scripts to issue
364: HTTP requests.</p>
1.12 avankest 365:
1.228 avankest 366: <pre class="idl">[NoInterfaceObject]
1.342 avankest 367: interface <dfn id="xmlhttprequesteventtarget">XMLHttpRequestEventTarget</dfn> : <span data-anolis-spec=dom>EventTarget</span> {
1.228 avankest 368: // for future use
369: };
370:
1.240 avankest 371: [<span title="dom-XMLHttpRequest">Constructor</span>]
1.228 avankest 372: interface <dfn id="xmlhttprequest">XMLHttpRequest</dfn> : <span>XMLHttpRequestEventTarget</span> {
1.330 avankest 373: // <a href="#event-handlers">event handler</a>
1.344 avankest 374: [TreatNonCallableAsNull] attribute <span data-anolis-spec=html>Function</span>? <span title="handler-xhr-onreadystatechange">onreadystatechange</span>;
1.58 avankest 375:
1.205 avankest 376: // <a href="#states">states</a>
1.272 avankest 377: const unsigned short <span title="dom-XMLHttpRequest-UNSENT">UNSENT</span> = 0;
378: const unsigned short <span title="dom-XMLHttpRequest-OPENED">OPENED</span> = 1;
379: const unsigned short <span title="dom-XMLHttpRequest-HEADERS_RECEIVED">HEADERS_RECEIVED</span> = 2;
380: const unsigned short <span title="dom-XMLHttpRequest-LOADING">LOADING</span> = 3;
381: const unsigned short <span title="dom-XMLHttpRequest-DONE">DONE</span> = 4;
1.277 avankest 382: readonly attribute unsigned short <span title="dom-XMLHttpRequest-readyState">readyState</span>;
1.58 avankest 383:
1.205 avankest 384: // <a href="#request">request</a>
1.340 avankest 385: void <span title="dom-XMLHttpRequest-open">open</span>(DOMString <var>method</var>, DOMString <var title>url</var>, optional boolean <var>async</var>, optional DOMString? <var>user</var>, optional DOMString? <var>password</var>);
1.279 avankest 386: void <span title="dom-XMLHttpRequest-setRequestHeader">setRequestHeader</span>(DOMString <var>header</var>, DOMString <var>value</var>);
1.271 avankest 387: void <span title="dom-XMLHttpRequest-send">send</span>();
1.342 avankest 388: void <span title="dom-XMLHttpRequest-send">send</span>(<span data-anolis-spec=dom>Document</span> <var>data</var>);
1.271 avankest 389: void <span title="dom-XMLHttpRequest-send">send</span>([AllowAny] DOMString? <var>data</var>);
1.275 avankest 390: void <span title="dom-XMLHttpRequest-abort">abort</span>();
1.58 avankest 391:
1.205 avankest 392: // <a href="#response">response</a>
1.276 avankest 393: readonly attribute unsigned short <span title="dom-XMLHttpRequest-status">status</span>;
394: readonly attribute DOMString <span title="dom-XMLHttpRequest-statusText">statusText</span>;
1.278 avankest 395: DOMString <span title="dom-XMLHttpRequest-getResponseHeader">getResponseHeader</span>(DOMString <var>header</var>);
396: DOMString <span title="dom-XMLHttpRequest-getAllResponseHeaders">getAllResponseHeaders</span>();
1.276 avankest 397: readonly attribute DOMString <span title="dom-XMLHttpRequest-responseText">responseText</span>;
1.305 avankest 398: readonly attribute <span>Document</span> <span title="dom-XMLHttpRequest-responseXML">responseXML</span>;
1.228 avankest 399: };</pre>
1.8 avankest 400:
1.235 avankest 401:
1.124 avankest 402:
1.334 avankest 403: <h3>Origin and base URL</h3>
1.203 avankest 404:
405: <p>Each <code>XMLHttpRequest</code> object has an associated
1.332 avankest 406: <dfn><code>XMLHttpRequest</code> origin</dfn> and an
407: <dfn><code>XMLHttpRequest</code> base URL</dfn>.
1.203 avankest 408:
409: <p>This specification defines their values when the global object is
1.332 avankest 410: represented by the <code data-anolis-spec=html>Window</code> object. When
411: the <code>XMLHttpRequest</code> object is used in other contexts their
412: values will have to be defined as appropriate for that context. That is
1.203 avankest 413: considered to be out of scope for this specification.</p>
414:
415: <p>In environments where the global object is represented by the
1.332 avankest 416: <code data-anolis-spec=html>Window</code> object the
417: <code>XMLHttpRequest</code> object has an associated
1.335 avankest 418: <dfn><code>XMLHttpRequest</code> document</dfn> which is the
1.342 avankest 419: <span data-anolis-spec=dom title=concept-document>document</span>
1.335 avankest 420: associated with the <code data-anolis-spec=html>Window</code> object for
421: which the <code>XMLHttpRequest</code> interface object was created.</p>
1.203 avankest 422:
423: <p class="note">The
1.335 avankest 424: <span><code>XMLHttpRequest</code> document</span> is used to
1.203 avankest 425: determine the <span><code>XMLHttpRequest</code> origin</span> and
426: <span><code>XMLHttpRequest</code> base URL</span> at a later stage.</p>
427:
428:
1.263 avankest 429:
1.350 avankest 430: <h3>Task sources</h3>
1.218 avankest 431:
1.350 avankest 432: <p>Each <code>XMLHttpRequest</code> object has its own
433: <span data-anolis-spec=html>task source</span>. Namely, the
434: <dfn><code>XMLHttpRequest</code> task source</dfn>.
1.203 avankest 435:
436:
1.211 avankest 437: <h3 id="constructors">Constructors</h3>
1.203 avankest 438:
1.263 avankest 439:
440:
1.270 avankest 441: <dl class="domintro">
1.330 avankest 442: <dt><var title>client</var> = new <code title="dom-XMLHttpRequest">XMLHttpRequest</code>()</dt>
1.270 avankest 443: <dd>Returns a new <code>XMLHttpRequest</code> object.</dd>
444:
445: </dl>
1.295 avankest 446:
1.351 avankest 447: <p>The <dfn title="dom-XMLHttpRequest"><code>XMLHttpRequest()</code></dfn>
448: constructor must return a new <code>XMLHttpRequest</code> object.
1.203 avankest 449:
1.263 avankest 450:
1.203 avankest 451:
1.336 avankest 452:
453:
454: <h3>Garbage collection</h3>
455:
456: <!-- Based on EventSource and WebSocket. Not sure what I am doing. -->
457:
458: <p>An <code>XMLHttpRequest</code> object must not be garbage collected if
1.341 avankest 459: its state is <span title=dom-XMLHttpRequest-OPENED>OPENED</span> and the
460: <span><code>send()</code> flag</span> is set, its state is
461: <span title=dom-XMLHttpRequest-HEADERS_RECEIVED>HEADERS_RECEIVED</span>, or
462: its state is <span title=dom-XMLHttpRequest-LOADING>LOADING</span>, and
463: it has one or more
1.342 avankest 464: <span data-anolis-spec=dom title=concept-event-listener>event listeners</span>
1.336 avankest 465: registered whose <b>type</b> is
1.337 avankest 466: <code title=event-xhr-readystatechange>readystatechange</code>.
1.336 avankest 467:
468: <p>If an <code>XMLHttpRequest</code> object is garbage collected while its
469: connection is still open, the user agent must cancel any instance of the
470: <span data-anolis-spec=html>fetch</span> algorithm opened by this object,
471: discarding any <span data-anolis-spec=html title=concept-task>tasks</span>
472: <span data-anolis-spec=html title="queue a task">queued</span> for them, and
473: discarding any further data received from the network for them.
474:
475:
476:
1.334 avankest 477: <h3 id="event-handlers">Event handlers</h3>
1.205 avankest 478:
1.248 avankest 479:
480:
1.205 avankest 481: <p>The following is the
1.332 avankest 482: <span data-anolis-spec=html title="event handlers">event handler</span>
483: (and its corresponding
484: <span data-anolis-spec=html>event handler event type</span>) that must be
485: supported as attribute by the
1.205 avankest 486: <code>XMLHttpRequest</code> object:</p>
487:
488: <table>
489: <thead>
490: <tr>
1.330 avankest 491: <th><span data-anolis-spec=html title="event handlers">event handler</span>
492: <th><span data-anolis-spec=html>event handler event type</span>
1.205 avankest 493: <tbody>
494: <tr>
1.332 avankest 495: <td><dfn title="handler-xhr-onreadystatechange"><code>onreadystatechange</code></dfn>
1.273 avankest 496: <td><code title="event-xhr-readystatechange">readystatechange</code></td>
1.205 avankest 497: </table>
498:
499:
500: <h3 id="states">States</h3>
1.295 avankest 501:
1.277 avankest 502: <dl class="domintro">
1.330 avankest 503: <dt><var title>client</var> . <code title="dom-XMLHttpRequest-readyState">readyState</code></dt>
1.277 avankest 504: <dd><p>Returns the current state.</p></dd>
505: </dl>
1.203 avankest 506:
507: <p>The <code>XMLHttpRequest</code> object can be in several states. The
1.332 avankest 508: <dfn title="dom-XMLHttpRequest-readyState"><code>readyState</code></dfn>
509: attribute must return the current state, which must be one of the
510: following values:</p>
1.203 avankest 511:
512: <dl>
1.332 avankest 513: <dt><dfn title="dom-XMLHttpRequest-UNSENT"><code>UNSENT</code></dfn>
1.203 avankest 514: (numeric value 0)</dt>
515: <dd><p>The object has been constructed.</p></dd>
516:
1.332 avankest 517: <dt><dfn title="dom-XMLHttpRequest-OPENED"><code>OPENED</code></dfn>
1.203 avankest 518: (numeric value 1)</dt>
1.274 avankest 519: <dd><p>The <code title="dom-XMLHttpRequest-open">open()</code> method has been successfully invoked.
1.203 avankest 520: During this state request headers can be set using
1.279 avankest 521: <code title="dom-XMLHttpRequest-setRequestHeader">setRequestHeader()</code>
522: and the request can be made using the
1.271 avankest 523: <code title="dom-XMLHttpRequest-send">send()</code> method.</p></dd>
1.203 avankest 524:
1.332 avankest 525: <dt><dfn title="dom-XMLHttpRequest-HEADERS_RECEIVED"><code>HEADERS_RECEIVED</code></dfn>
1.203 avankest 526: (numeric value 2)</dt>
1.257 avankest 527: <dd><p>All redirects (if any) have been followed and all HTTP headers of
528: the final response have been received. Several response members of the
529: object are now available.</p></dd>
1.203 avankest 530:
1.332 avankest 531: <dt><dfn title="dom-XMLHttpRequest-LOADING"><code>LOADING</code></dfn>
1.203 avankest 532: (numeric value 3)</dt>
533: <dd><p>The <span>response entity body</span> is being received.</p></dd>
534:
1.332 avankest 535: <dt><dfn title="dom-XMLHttpRequest-DONE"><code>DONE</code></dfn>
1.203 avankest 536: (numeric value 4)</dt>
537: <dd><p>The data transfer has been completed or something went wrong
538: during the transfer (e.g. infinite redirects).</p></dd>
539: </dl>
540:
1.272 avankest 541: <p>The <span title="dom-XMLHttpRequest-OPENED">OPENED</span> state has an associated
1.203 avankest 542: <dfn id="send-flag"><code>send()</code> flag</dfn> that indicates whether
1.271 avankest 543: the <code title="dom-XMLHttpRequest-send">send()</code> method has been
544: invoked. It can be either true or false and has an initial value of
545: false.</p>
1.203 avankest 546:
1.310 avankest 547: <p>The <dfn id="error-flag">error flag</dfn> indicates some type of
548: network error or abortion. It is used during the
549: <span title="dom-XMLHttpRequest-DONE">DONE</span> state. It can be either
550: true or false and has an initial value of false.</p>
1.203 avankest 551:
552:
1.205 avankest 553: <h3 id="request">Request</h3>
1.203 avankest 554:
555: <p>The <code>XMLHttpRequest</code> object holds the following request
556: metadata variables:</p>
557:
1.204 avankest 558: <dl>
1.348 avankest 559: <dt>The <dfn>synchronous flag</dfn></dt>
560: <dd>Set when <span data-anolis-spec=html title=fetch>fetching</span> is
561: done synchronously. Initially unset.</dd>
1.204 avankest 562:
563: <dt>The <dfn>request method</dfn></dt>
1.310 avankest 564: <dd>The HTTP method used in the request.</dd>
1.204 avankest 565:
566: <dt>The <dfn>request URL</dfn></dt>
1.330 avankest 567: <dd>The resolved <span data-anolis-spec=html>URL</span> used in the
568: request.</dd>
1.218 avankest 569:
1.204 avankest 570: <dt>The <dfn>request username</dfn></dt>
571: <dd>The username used in the request or null if there is no
572: username.</dd>
1.218 avankest 573:
1.204 avankest 574: <dt>The <dfn>request password</dfn></dt>
575: <dd>The password used in the request or null if there is no
576: password.</dd>
1.218 avankest 577:
1.204 avankest 578: <dt>The <dfn id="author-request-headers">author request headers</dfn></dt>
579: <dd>A list consisting of HTTP header name/value pairs to be used in the
580: request.</p>
1.203 avankest 581:
1.204 avankest 582: <dt>The <dfn>request entity body</dfn></dt>
1.330 avankest 583: <dd>The <span data-anolis-spec=http>entity body</span> used in the
584: request or null if there is no
585: <span data-anolis-spec=http>entity body</span>.</dd>
1.295 avankest 586:
1.248 avankest 587:
1.204 avankest 588: </dl>
1.203 avankest 589:
1.248 avankest 590:
591:
1.203 avankest 592:
1.330 avankest 593: <h4>The <code title>open()</code> method</h4>
1.295 avankest 594:
1.269 avankest 595: <dl class="domintro">
1.330 avankest 596: <dt><var title>client</var> . <code title="dom-XMLHttpRequest-open">open(<var title>method</var>,
597: <var title>url</var>, <var title>async</var>, <var title>user</var>,
598: <var title>password</var>)</code></dt>
1.269 avankest 599:
1.280 avankest 600: <dd>
601: <p>Sets the <span>request method</span>, <span>request URL</span>,
1.348 avankest 602: <span>synchronous flag</span>, <span>request username</span>, and
1.280 avankest 603: <span>request password</span>.</p>
1.295 avankest 604:
1.343 avankest 605: <p>Throws a "<code data-anolis-spec=dom>SyntaxError</code>" exception if
606: one of the following is true:</p>
1.295 avankest 607:
1.280 avankest 608: <ul>
1.330 avankest 609: <li><var title>method</var> is not a valid HTTP method.</li>
610: <li><var title>url</var> cannot be resolved.</li>
611: <li><var title>url</var> contains the <code>"user:password"</code>
612: format in the <code data-anolis-spec=uri>userinfo</code> production.
1.280 avankest 613: </ul>
1.295 avankest 614:
1.343 avankest 615: <p>Throws a "<code data-anolis-spec=dom>SecurityError</code>" exception
616: if <var title>method</var> is a case-insensitive match for
1.280 avankest 617: <code>CONNECT</code>, <code>TRACE</code> or <code>TRACK</code>.</p>
1.295 avankest 618:
1.343 avankest 619: <p>Throws an "<code data-anolis-spec=dom>InvalidAccessError</code>"
1.351 avankest 620: exception if one of the following is true:</p>
621:
622: <ul>
623: <li>Either <var title>user</var> or <var title>password</var> is passed
624: as argument and the <span data-anolis-spec=html>origin</span> of
625: <var title>url</var> does not match the
626: <span><code>XMLHttpRequest</code> origin</span>.
627: <li>There is an associated
628: <span><code>XMLHttpRequest</code> document</span> and either the
629: <code title=dom-XMLHttpRequest-timeout>timeout</code> attribute is not
630: zero, the
631: <code title=dom-XMLHttpRequest-withCredentials>withCredentials</code>
632: attribute is true, or the
633: <code title=dom-XMLHttpRequest-responseType>responseType</code>
634: attribute is not the empty string.
635: </ul>
1.280 avankest 636: </dd>
1.269 avankest 637: </dl>
1.88 avankest 638:
1.351 avankest 639: <p>The
1.330 avankest 640: <dfn id="dom-xmlhttprequest-open" title="dom-XMLHttpRequest-open"><code>open(<var title>method</var>, <var title>url</var>, <var title>async</var>, <var title>user</var>, <var title>password</var>)</code></dfn>
1.351 avankest 641: method must run these steps (unless otherwise indicated):</p>
1.90 avankest 642:
1.88 avankest 643: <ol>
1.203 avankest 644: <li>
1.349 avankest 645: <p>If there is an associated
1.335 avankest 646: <span><code>XMLHttpRequest</code> document</span> run
1.203 avankest 647: these substeps:</p>
1.90 avankest 648:
1.203 avankest 649: <ol>
650: <li><p>If the
1.335 avankest 651: <span><code>XMLHttpRequest</code> document</span> is not
1.342 avankest 652: <span data-anolis-spec=html>fully active</span>,
653: <span data-anolis-spec=dom title=concept-throw>throw</span> an
1.343 avankest 654: "<code data-anolis-spec=dom>InvalidStateError</code>" exception and
655: terminate the overall set of steps.
1.203 avankest 656:
657: <li><p>Let <span><code>XMLHttpRequest</code> base URL</span> be the
1.330 avankest 658: <span data-anolis-spec=html>document base URL</span> of the
1.335 avankest 659: <span><code>XMLHttpRequest</code> document</span>.</p></li>
1.203 avankest 660:
661: <li><p>Let <span><code>XMLHttpRequest</code> origin</span> be the
1.330 avankest 662: <span data-anolis-spec=html>origin</span> of the
1.335 avankest 663: <span><code>XMLHttpRequest</code> document</span>.</p></li>
1.203 avankest 664: </ol>
665: </li>
1.90 avankest 666:
1.256 avankest 667: <li><p>If any code point in <var>method</var> is higher than
668: U+00FF LATIN SMALL LETTER Y WITH DIAERESIS or after
1.294 avankest 669: <span title="deflate a DOMString into a byte sequence">deflating</span>
1.256 avankest 670: <var>method</var> it does not match the
1.342 avankest 671: <span data-anolis-spec=http>Method</span> token production,
672: <span data-anolis-spec=dom title=concept-throw>throw</span> a
1.343 avankest 673: "<code data-anolis-spec=dom>SyntaxError</code>" exception and terminate
674: these steps. Otherwise let <var>method</var> be the result of
1.294 avankest 675: <span title="deflate a DOMString into a byte sequence">deflating</span>
1.256 avankest 676: <var>method</var>.</p></li> <!-- This sounds lame, but it works. -->
1.118 avankest 677:
1.115 avankest 678: <li>
1.256 avankest 679: <p>If <var>method</var> is a case-insensitive match for
1.203 avankest 680: <code>CONNECT</code>, <code>DELETE</code>, <code>GET</code>,
681: <code>HEAD</code>, <code>OPTIONS</code>, <code>POST</code>,
682: <code>PUT</code>, <code>TRACE</code>, or <code>TRACK</code>
1.256 avankest 683: subtract 0x20 from each byte in the range 0x61 (ASCII a) to
684: 0x7A (ASCII z).</p>
1.118 avankest 685:
1.203 avankest 686: <p class="note">If it does not match any of the above, it is passed
687: through <em>literally</em>, including in the final request.</p>
1.115 avankest 688: </li>
1.203 avankest 689: <!-- WebKit (and supposedly Gecko) also uppercase: COPY, INDEX, LOCK,
690: M-POST, MKCOL, MOVE, PROPFIND, PROPPATCH, and UNLOCK. -->
1.118 avankest 691:
1.111 avankest 692: <li>
1.256 avankest 693: <p>If <var>method</var> is a case-sensitive match for
1.342 avankest 694: <code>CONNECT</code>, <code>TRACE</code>, or <code>TRACK</code>,
695: <span data-anolis-spec=dom title=concept-throw>throw</span> a
1.343 avankest 696: "<code data-anolis-spec=dom>SecurityError</code>" exception and
697: terminate these steps.
1.117 avankest 698:
1.203 avankest 699: <p class="note">Allowing these methods poses a security risk.
1.330 avankest 700: <span data-anolis-ref>HTTPVERBSEC</span>
1.111 avankest 701: </li>
702:
1.330 avankest 703: <li><p>Let <var title>url</var> be a
704: <span data-anolis-spec=html>URL</span> with character encoding UTF-8.
1.113 avankest 705:
1.330 avankest 706: <li><p><span title="Resolve a URL">Resolve</span> <var title>url</var>
1.203 avankest 707: relative to the <span><code>XMLHttpRequest</code> base URL</span>.
1.342 avankest 708: If the algorithm returns an error,
709: <span data-anolis-spec=dom title=concept-throw>throw</span> a
1.343 avankest 710: "<code data-anolis-spec=dom>SyntaxError</code>" exception and terminate
711: these steps.
1.203 avankest 712:
713: <!-- Presto and Gecko override the encoding. WebKit does not. Trident
714: does not support non-ASCII URLs. This matters for the <query> component,
1.322 avankest 715: see HTML. -->
1.203 avankest 716:
1.330 avankest 717: <li><p>Drop
718: <code data-anolis-spec=html title=url-fragment><fragment></code> from
719: <var title>url</var>.</p></li>
1.203 avankest 720:
721: <li><p>If the <code>"user:password"</code> format in the
1.330 avankest 722: <code data-anolis-spec=uri>userinfo</code> production is not supported
723: for the relevant
724: <code data-anolis-spec=html title=url-scheme><scheme></code> and
1.342 avankest 725: <var title>url</var> contains this format,
726: <span data-anolis-spec=dom title=concept-throw>throw</span> a
1.343 avankest 727: "<code data-anolis-spec=dom>SyntaxError</code>" and terminate these
728: steps.
1.203 avankest 729:
1.310 avankest 730: <!-- XXX need to throw here for "user:password" or just "user" for
731: cross-origin unless we solve this in another way -->
732:
1.330 avankest 733: <li><p>If <var title>url</var> contains the <code>"user:password"</code>
1.203 avankest 734: format let <var>temp user</var> be the user part and
735: <var>temp password</var> be the password part.</p></li>
736:
1.330 avankest 737: <li><p>If <var title>url</var> just contains the <code>"user"</code>
1.203 avankest 738: format let <var>temp user</var> be the user part.</p></li>
739:
1.349 avankest 740: <li>
741: <p>Let <var>async</var> be the value of the <var>async</var> argument or
742: true if it was omitted.
743:
744:
1.203 avankest 745:
746: <li>
1.330 avankest 747: <p>If the <var title>user</var> argument was not omitted follow these
1.300 avankest 748: sub steps:</p>
1.90 avankest 749:
1.203 avankest 750: <ol>
1.330 avankest 751: <li><p>If <var title>user</var> is not null and the
752: <span data-anolis-spec=html>origin</span> of <var title>url</var> is not
753: <span data-anolis-spec=html>same origin</span> with the
1.342 avankest 754: <span><code>XMLHttpRequest</code> origin</span>,
755: <span data-anolis-spec=dom title=concept-throw>throw</span> an
1.343 avankest 756: "<code data-anolis-spec=dom>InvalidAccessError</code>" exception and
757: terminate the overall set of steps.
1.263 avankest 758:
1.300 avankest 759: <li><p>Let <var>temp user</var> be <var>user</var>.</p></li>
1.203 avankest 760: </ol>
1.88 avankest 761:
1.203 avankest 762: <p class="note">These steps override anything that may have been set by
1.330 avankest 763: the <var title>url</var> argument.</p>
1.203 avankest 764: </li>
1.88 avankest 765:
1.128 avankest 766: <li>
1.330 avankest 767: <p>If the <var title>password</var> argument was not omitted follow
1.300 avankest 768: these sub steps:</p>
1.203 avankest 769:
770: <ol>
1.330 avankest 771: <li><p>If <var title>password</var> is not null and the
772: <span data-anolis-spec=html>origin</span> of <var title>url</var> is not
773: <span data-anolis-spec=html>same origin</span> with the
1.342 avankest 774: <span><code>XMLHttpRequest</code> origin</span>,
775: <span data-anolis-spec=dom title=concept-throw>throw</span> an
1.343 avankest 776: "<code data-anolis-spec=dom>InvalidAccessError</code>" exception and
777: terminate the overall set of steps.</p></li>
1.263 avankest 778:
1.300 avankest 779: <li><p>Let <var>temp password</var> be <var>password</var>.</p></li>
1.203 avankest 780: </ol>
781:
782: <p class="note">These steps override anything that may have been set by
1.330 avankest 783: the <var title>url</var> argument.</p>
1.128 avankest 784: </li>
1.88 avankest 785:
1.314 avankest 786: <li><p><span title="terminate abort()">Terminate the <code>abort()</code> algorithm</span>.</p></li>
787:
788: <li><p><span title="terminate send()">Terminate the <code>send()</code> algorithm</span>.</p></li>
1.203 avankest 789:
1.330 avankest 790: <li><p>The user agent should cancel any network
1.203 avankest 791: activity for which the object is responsible.</p></li>
792: <!-- we can hardly require it... -->
793:
1.330 avankest 794: <li><p>If there are any
795: <span data-anolis-spec=html title=concept-task>tasks</span> from the
796: object's <span><code>XMLHttpRequest</code> task source</span> in one of
797: the <span data-anolis-spec=html title="task queue">task queues</span>,
798: then remove them.
1.252 avankest 799:
1.203 avankest 800: <li>
801: <p>Set variables associated with the object as follows:</p>
802:
803: <ul>
804:
805: <li><p>Set the <span>request method</span> to <var>method</var>.</p></li>
806:
1.330 avankest 807: <li><p>Set the <span>request URL</span> to <var title>url</var>.</p></li>
1.58 avankest 808:
1.348 avankest 809: <li><p>If <var>async</var> is false, set the
810: <span>synchronous flag</span>.
1.303 avankest 811:
1.203 avankest 812: <li><p>Set the <span>request username</span> to <var>temp user</var>.</p></li>
1.12 avankest 813:
1.203 avankest 814: <li><p>Set the <span>request password</span> to <var>temp password</var>.</p></li>
1.12 avankest 815:
1.303 avankest 816: <li><p>Empty the list of <span>author request headers</span>.</p>
817:
818: <li><p>Set the <span><code>send()</code> flag</span> to false.</p></li>
819:
820: <li><p>Set <span>response entity body</span> to null.</p></li>
1.203 avankest 821: </ul>
822: </li>
1.58 avankest 823:
1.346 avankest 824: <li><p>Change the state to
1.272 avankest 825: <span title="dom-XMLHttpRequest-OPENED">OPENED</span>.</p></li>
1.58 avankest 826:
1.342 avankest 827: <li><p><span data-anolis-spec=dom title=concept-event-fire>Fire an event</span> named <code title=event-xhr-readystatechange>readystatechange</code>.</p></li>
1.203 avankest 828: </ol>
1.280 avankest 829:
1.58 avankest 830:
1.14 avankest 831:
1.330 avankest 832: <h4>The <code title>setRequestHeader()</code> method</h4>
1.12 avankest 833:
1.270 avankest 834: <dl class="domintro">
1.330 avankest 835: <dt><var title>client</var> . <code title="dom-XMLHttpRequest-setRequestHeader">setRequestHeader(<var title>header</var>, <var title>value</var>)</code></dt>
1.280 avankest 836:
1.270 avankest 837: <dd>
838: <p>Appends an header to the list of
1.310 avankest 839: <span>author request headers</span>, or if <var>header</var> is already
840: in the list of <span>author request headers</span>, combines its value
841: with <var>value</var>.</p>
1.280 avankest 842:
1.343 avankest 843: <p>Throws an "<code data-anolis-spec=dom>InvalidStateError</code>"
844: exception if the state is not
845: <span title="dom-XMLHttpRequest-OPENED">OPENED</span> or if the
1.280 avankest 846: <span><code>send()</code> flag</span> is true.</p>
847:
1.343 avankest 848: <p>Throws a "<code data-anolis-spec=dom>SyntaxError</code>" exception if
1.330 avankest 849: <var title>header</var> is not a valid HTTP header field name or if
850: <var title>value</var> is not a valid HTTP header field value.</p>
1.270 avankest 851: </dd>
852: </dl>
1.45 avankest 853:
1.279 avankest 854: <p class="note">As indicated in the algorithm below certain headers cannot
855: be set and are left up to the user agent. In addition there are certain
856: other headers the user agent will take control of if they are not set by
857: the author as indicated at the end of the
1.271 avankest 858: <code title="dom-XMLHttpRequest-send">send()</code> method section.</p>
1.203 avankest 859:
1.248 avankest 860:
861:
1.351 avankest 862: <p>The
1.330 avankest 863: <dfn id="dom-xmlhttprequest-setrequestheader" title="dom-XMLHttpRequest-setRequestHeader"><code>setRequestHeader(<var title>header</var>, <var title>value</var>)</code></dfn>
1.351 avankest 864: method must run these steps:</p>
1.14 avankest 865:
1.203 avankest 866: <ol>
1.342 avankest 867: <li><p>If the state is not
868: <span title="dom-XMLHttpRequest-OPENED">OPENED</span>,
869: <span data-anolis-spec=dom title=concept-throw>throw</span> an
1.343 avankest 870: "<code data-anolis-spec=dom>InvalidStateError</code>" exception and
871: terminate these steps.
1.342 avankest 872:
873: <li><p>If the <span><code>send()</code> flag</span> is true,
874: <span data-anolis-spec=dom title=concept-throw>throw</span> an
1.343 avankest 875: "<code data-anolis-spec=dom>InvalidStateError</code>" exception and
876: terminate these steps.
1.203 avankest 877:
1.256 avankest 878: <li><p>If any code point in <var>header</var> is higher than
879: U+00FF LATIN SMALL LETTER Y WITH DIAERESIS or after
1.294 avankest 880: <span title="deflate a DOMString into a byte sequence">deflating</span>
1.256 avankest 881: <var>header</var> it does not match the
1.342 avankest 882: <span data-anolis-spec=http>field-name</span> production,
883: <span data-anolis-spec=dom title=concept-throw>throw</span> a
1.343 avankest 884: "<code data-anolis-spec=dom>SyntaxError</code>" exception and terminate
885: these steps. Otherwise let <var>header</var> be the result of
1.294 avankest 886: <span title="deflate a DOMString into a byte sequence">deflating</span>
1.256 avankest 887: <var>header</var>.</p></li> <!-- This sounds lame, but it works. -->
1.203 avankest 888:
889: <li>
1.256 avankest 890: <p>If any code point in <var>value</var> is higher than
891: U+00FF LATIN SMALL LETTER Y WITH DIAERESIS or after
1.294 avankest 892: <span title="deflate a DOMString into a byte sequence">deflating</span>
1.256 avankest 893: <var>value</var> it does not match the
1.342 avankest 894: <span data-anolis-spec=http>field-value</span> production,
895: <span data-anolis-spec=dom title=concept-throw>throw</span> a
1.343 avankest 896: "<code data-anolis-spec=dom>SyntaxError</code>" exception and terminate
897: these steps. Otherwise let <var>value</var> be the result of
1.294 avankest 898: <span title="deflate a DOMString into a byte sequence">deflating</span>
1.256 avankest 899: <var>value</var>.</p> <!-- This sounds lame, but it works. -->
1.203 avankest 900:
901: <p class="note">The empty string is legal and represents the empty
902: header value.</p>
903: </li>
904:
905: <li>
1.259 avankest 906: <p>Terminate these steps if <var>header</var> is a case-insensitive
907: match for one of the following headers:</p>
1.203 avankest 908:
909: <ul>
910: <li><code>Accept-Charset</code></li>
911: <li><code>Accept-Encoding</code></li>
1.352 avankest 912: <li><code>Access-Control-Request-Headers</code></li>
913: <li><code>Access-Control-Request-Method</code></li>
1.203 avankest 914: <li><code>Connection</code></li>
915: <li><code>Content-Length</code></li>
916: <li><code>Cookie</code></li>
917: <li><code>Cookie2</code></li>
918: <li><code>Content-Transfer-Encoding</code></li>
919: <li><code>Date</code></li>
920: <li><code>Expect</code></li>
921: <li><code>Host</code></li>
922: <li><code>Keep-Alive</code></li>
1.352 avankest 923: <li><code title>Origin</code></li>
1.203 avankest 924: <li><code>Referer</code></li>
925: <li><code>TE</code></li>
926: <li><code>Trailer</code></li>
927: <li><code>Transfer-Encoding</code></li>
928: <li><code>Upgrade</code></li>
929: <li><code>User-Agent</code></li>
930: <li><code>Via</code></li>
931: </ul>
1.96 avankest 932:
1.256 avankest 933: <p>… or if the start of <var>header</var> is a case-insensitive
934: match for <code>Proxy-</code> or <code>Sec-</code> (including when
935: <var>header</var> is just <code>Proxy-</code> or <code>Sec-</code>).</p>
1.203 avankest 936:
1.280 avankest 937: <p class="note">The above headers are controlled by the user agent to
938: let it control those aspects of transport. This guarantees data
939: integrity to some extent. Header names starting with <code>Sec-</code>
940: are not allowed to be set to allow new headers to be minted that are
941: guaranteed not to come from <code>XMLHttpRequest</code>.</p>
1.203 avankest 942: </li>
1.14 avankest 943:
1.203 avankest 944: <li><p>If <var>header</var> is not in the
945: <span>author request headers</span> list append <var>header</var> with
946: its associated <var>value</var> to the list and terminate these
947: steps.</p></li>
948:
949: <li><p>If <var>header</var> is in the <span>author request headers</span>
950: list either use multiple headers, combine the values or use a combination
951: of those (section 4.2, RFC 2616).
1.330 avankest 952: <span data-anolis-ref>HTTP</span>
1.203 avankest 953: <!-- XXX it seems UAs always combine the values -->
954: </ol>
1.45 avankest 955:
1.271 avankest 956: <p class="note">See also the
957: <code title="dom-XMLHttpRequest-send">send()</code> method regarding user
1.203 avankest 958: agent header handling for caching, authentication, proxies, and
959: cookies.</p>
1.14 avankest 960:
1.203 avankest 961: <div class="example">
1.312 avankest 962: <p>Some simple code demonstrating what happens when setting the same
963: header twice:</p>
964:
1.203 avankest 965: <pre><code>// The following script:
1.14 avankest 966: var client = new XMLHttpRequest();
967: client.open('GET', 'demo.cgi');
968: client.setRequestHeader('X-Test', 'one');
969: client.setRequestHeader('X-Test', 'two');
970: client.send();
971:
1.312 avankest 972: // …results in the following header being sent:
973: X-Test: one, two</code></pre>
1.203 avankest 974: </div>
1.255 avankest 975:
1.248 avankest 976:
1.218 avankest 977:
1.203 avankest 978:
1.330 avankest 979: <h4>The <code title>send()</code> method</h4>
1.12 avankest 980:
1.271 avankest 981: <dl class="domintro">
1.330 avankest 982: <dt><var title>client</var> . <code title="dom-XMLHttpRequest-send">send(<var title>data</var>)</code></dt>
1.280 avankest 983: <dd>
984: <p>Initiates the request. The optional argument provides the
985: <span>request entity body</span>. The argument is ignored if
986: <span>request method</span> is <code>GET</code> or
987: <code>HEAD</code>.</p>
988:
1.343 avankest 989: <p>Throws an "<code data-anolis-spec=dom>InvalidStateError</code>"
990: exception if the state is not
991: <span title="dom-XMLHttpRequest-OPENED">OPENED</span> or if the
992: <span><code>send()</code> flag</span> is true.</p>
1.280 avankest 993: </dd>
1.271 avankest 994: </dl>
1.203 avankest 995:
1.351 avankest 996: <p>The
1.331 avankest 997: <dfn title="dom-XMLHttpRequest-send"><code>send(<var>data</var>)</code></dfn>
1.351 avankest 998: method must run these steps (unless otherwise noted). This algorithm can
999: be <dfn title="terminate send()">terminated</dfn> by invoking the
1.314 avankest 1000: <code title="dom-XMLHttpRequest-open">open()</code> or
1001: <code title="dom-XMLHttpRequest-abort">abort()</code> method. When it is
1002: <span title="terminate send()">terminated</span> the user agent
1.351 avankest 1003: must terminate the algorithm after finishing the step it is on.</p>
1.314 avankest 1004:
1005: <p class="note">The <code title="dom-XMLHttpRequest-send">send()</code>
1.351 avankest 1006: algorithm can only be terminated if the <span>synchronous flag</span> is
1007: unset and only after the method call has returned.</p>
1.181 avankest 1008:
1.203 avankest 1009: <ol>
1.342 avankest 1010: <li><p>If the state is not
1011: <span title="dom-XMLHttpRequest-OPENED">OPENED</span>,
1012: <span data-anolis-spec=dom title=concept-throw>throw</span> an
1.343 avankest 1013: "<code data-anolis-spec=dom>InvalidStateError</code>" exception and
1014: terminate these steps.
1.342 avankest 1015:
1016: <li><p>If the <span><code>send()</code> flag</span> is true,
1017: <span data-anolis-spec=dom title=concept-throw>throw</span> an
1.343 avankest 1018: "<code data-anolis-spec=dom>InvalidStateError</code>" exception and
1019: terminate these steps.
1.58 avankest 1020:
1.203 avankest 1021: <li>
1.280 avankest 1022: <p>If the <span>request method</span> is a case-sensitive match for
1.330 avankest 1023: <code>GET</code> or <code>HEAD</code> act as if <var title>data</var>
1.280 avankest 1024: is null.</p>
1.295 avankest 1025:
1.232 avankest 1026: <p>If the <var>data</var> argument has been omitted or is
1.239 avankest 1027: null, do not include a <span>request entity body</span>
1.232 avankest 1028: and go to the next step.</p>
1.248 avankest 1029:
1030: <p>Otherwise, let <var>encoding</var> be null, <var>mime type</var> be
1031: null, and then follow these rules:</p>
1.203 avankest 1032:
1033: <dl class="switch">
1.248 avankest 1034:
1.295 avankest 1035:
1.342 avankest 1036: <dt>If <var>data</var> is a <code data-anolis-spec=dom>Document</code>
1.203 avankest 1037:
1038: <dd>
1.330 avankest 1039: <p>Let <var>encoding</var> be the
1.342 avankest 1040: <span data-anolis-spec=dom>preferred MIME name</span> of the
1041: <span data-anolis-spec=dom title=concept-document-character-encoding>character encoding</span>
1.232 avankest 1042: of <var>data</var>. If <var>encoding</var> is UTF-16 change it to
1043: UTF-8.</p>
1.295 avankest 1044:
1.302 avankest 1045: <p>Let <var>mime type</var> be "<code>application/xml</code>" or
1.330 avankest 1046: "<code>text/html</code>" if
1.342 avankest 1047: <code data-anolis-spec=dom>Document</code> is an
1048: <span data-anolis-spec=dom>HTML document</span>, followed by
1.302 avankest 1049: "<code>;charset=</code>", followed by <var>encoding</var>.</p>
1.232 avankest 1050:
1051: <p>Let the <span>request entity body</span> be the result of getting
1.342 avankest 1052: the <code>innerHTML</code>
1.330 avankest 1053: attribute on <var>data</var>
1054: <span data-anolis-spec=webidl title="convert a DOMString to a sequence of Unicode characters">converted to Unicode</span>
1.342 avankest 1055: and encoded as <var>encoding</var>. Re-throw any exception this
1056: throws.</p> <!-- XXX replace innerHTML somehow -->
1.218 avankest 1057:
1.233 avankest 1058: <p class="note">In particular, if the document cannot be serialized an
1.343 avankest 1059: "<code data-anolis-spec=dom>InvalidStateError</code>" exception is
1060: thrown.</p>
1.217 avankest 1061:
1.330 avankest 1062: <p class="note">Subsequent changes to the
1.342 avankest 1063: <code data-anolis-spec=dom>Document</code> have no effect on what
1.330 avankest 1064: is transferred.</p>
1.203 avankest 1065: </dd>
1.237 avankest 1066:
1.248 avankest 1067: <dt>If <var>data</var> is a <code>DOMString</code></dt>
1.237 avankest 1068:
1.248 avankest 1069: <dd>
1070: <p>Let <var>encoding</var> be UTF-8.</p>
1.295 avankest 1071:
1.248 avankest 1072: <p>Let <var>mime type</var> be "<code>text/plain;charset=UTF-8</code>".</p>
1073:
1074: <p>Let the <span>request entity body</span> be <var>data</var>
1.330 avankest 1075: <span data-anolis-spec=webidl title="convert a DOMString to a sequence of Unicode characters">converted to Unicode</span>
1.248 avankest 1076: and encoded as UTF-8.</p>
1077: </dd>
1078:
1079:
1.203 avankest 1080: </dl>
1.58 avankest 1081:
1.352 avankest 1082: <p>If a <code>Content-Type</code> header is in
1083: <span>author request headers</span> and its value is a
1084: <span data-anolis-spec=html>valid MIME type</span> that has a
1085: <code>charset</code> parameter whose value is not a case-insensitive
1.330 avankest 1086: match for <var title>encoding</var>, and <var title>encoding</var>
1.352 avankest 1087: is not null, set all the <code>charset</code> parameters of that
1088: <code>Content-Type</code> header to <var title>encoding</var>.
1.232 avankest 1089:
1.352 avankest 1090: <p>If no <code>Content-Type</code> header is in
1091: <span>author request headers</span> and <var title>mime type</var> is
1092: not null, append a <code>Content-Type</code> header with value
1093: <var title>mime type</var> to <span>author request headers</span>.
1.236 avankest 1094:
1095: <!-- reminder: if we ever change this to always include charset it has
1096: to be included as the first parameter for compatibility reasons -->
1.203 avankest 1097: </li>
1.202 avankest 1098:
1.348 avankest 1099: <li><p>If the <span>synchronous flag</span> is set release the
1.330 avankest 1100: <span data-anolis-spec=html>storage mutex</span>.</p></li>
1.103 avankest 1101:
1.248 avankest 1102:
1103:
1.203 avankest 1104: <li><p>Set the <span>error flag</span> to false.</p></li>
1.218 avankest 1105:
1.248 avankest 1106:
1107:
1.211 avankest 1108: <li>
1.348 avankest 1109: <p>If the <span>synchronous flag</span> is unset, run these substeps:</p>
1.218 avankest 1110:
1.211 avankest 1111: <ol>
1.217 avankest 1112: <li><p>Set the <span><code>send()</code> flag</span> to true.</p></li>
1113:
1.211 avankest 1114: <li>
1.342 avankest 1115: <p><span data-anolis-spec=dom title=concept-event-fire>Fire an event</span> named <code title=event-xhr-readystatechange>readystatechange</code>.
1.145 avankest 1116:
1.211 avankest 1117: <p class="note">The state does not change. The event is dispatched for
1118: historical reasons.</p>
1119: </li>
1120:
1.248 avankest 1121:
1122:
1.271 avankest 1123: <li><p>Return the <code title="dom-XMLHttpRequest-send">send()</code>
1124: method call, but continue running the steps in this algorithm.</p></li>
1.211 avankest 1125: </ol>
1126: </li>
1.218 avankest 1127:
1.203 avankest 1128: <li>
1.300 avankest 1129: <dl class="switch">
1130: <dt>If the <span><code>XMLHttpRequest</code> origin</span> and the
1.330 avankest 1131: <span>request URL</span> are <span data-anolis-spec=html>same origin</span></dt>
1.300 avankest 1132:
1133: <dd>
1134: <p>These are the <dfn>same-origin request steps</dfn>.</p>
1.211 avankest 1135:
1.330 avankest 1136: <p><span data-anolis-spec=html>Fetch</span> the
1137: <span>request URL</span> from <i title>origin</i>
1.260 avankest 1138: <span><code>XMLHttpRequest</code> origin</span>, with the
1.330 avankest 1139: <i title>synchronous flag</i> set if the
1.348 avankest 1140: <span>synchronous flag</span> is set, using HTTP method
1.248 avankest 1141: <span>request method</span>, user <span>request username</span> (if
1142: non-null) and password <span>request password</span> (if non-null),
1143: taking into account the <span>request entity body</span>, list of
1144: <span>author request headers</span> and the rules listed at the end of
1145: this section.</p>
1146:
1147: <dl class="switch">
1.348 avankest 1148: <dt>If the <span>synchronous flag</span> is set</dt>
1.248 avankest 1149: <dd>
1150: <p>While making the request also follow the
1151: <span>same-origin request event rules</span>.</p>
1152:
1153: <!--
1154: This cannot involve any task queue whatsoever because that would
1155: mean other tasks on the task queue might get processed as well
1156: which is counter to the whole idea of doing things synchronous.
1157: -->
1158:
1.271 avankest 1159: <p class="note">The
1160: <code title="dom-XMLHttpRequest-send">send()</code> method call will
1161: now be returned by virtue of this algorithm ending.</p>
1.248 avankest 1162: </dd>
1163:
1.348 avankest 1164: <dt>If the <span>synchronous flag</span> is unset</dt>
1.248 avankest 1165: <dd>
1.300 avankest 1166:
1.248 avankest 1167:
1168: <p>While processing the request, as data becomes available and when
1169: the user interferes with the request,
1.330 avankest 1170: <span data-anolis-spec=html title="queue a task">queue tasks</span>
1171: to update the <span>response entity body</span> and follow the
1.254 avankest 1172: <span>same-origin request event rules</span>.</p>
1.248 avankest 1173: </dd>
1174: </dl>
1.300 avankest 1175: </dd>
1176:
1177: <dt>Otherwise</dt>
1178: <dd>
1179: <p>These are the <dfn>cross-origin request steps</dfn>.</p>
1180:
1181:
1182: <p>This is a <span>network error</span>.</p>
1183:
1184:
1185:
1186: </dd>
1187: </dl>
1.203 avankest 1188: </li>
1189: </ol>
1.60 avankest 1190:
1.203 avankest 1191: <hr>
1192:
1.227 avankest 1193: <p>If the user agent allows the end user to configure a proxy it
1.330 avankest 1194: should modify the request appropriately; i.e., connect
1.248 avankest 1195: to the proxy host instead of the origin server, modify the
1196: <code>Request-Line</code> and send <code>Proxy-Authorization</code>
1197: headers as specified.</p>
1.295 avankest 1198:
1.262 avankest 1199: <hr>
1.212 avankest 1200:
1.218 avankest 1201: <p>If the user agent supports HTTP Authentication and
1.262 avankest 1202: <code title="http-authorization">Authorization</code> is not in the list
1.330 avankest 1203: of <span>author request headers</span>, it should
1.218 avankest 1204: consider requests originating from the <code>XMLHttpRequest</code> object
1205: to be part of the protection space that includes the accessed URIs and
1.262 avankest 1206: send <code title="http-authorization">Authorization</code> headers and
1207: handle <code>401 Unauthorized</code> requests appropriately.</p>
1208:
1209: <p>If authentication fails,
1.311 avankest 1210: <span><code>XMLHttpRequest</code> origin</span> and the
1.330 avankest 1211: <span>request URL</span> are <span data-anolis-spec=html>same origin</span>,
1.262 avankest 1212: <code title="http-authorization">Authorization</code> is not in the list
1213: of <span>author request headers</span>, <span>request username</span> is
1214: null, and <span>request password</span> is null, user agents
1.330 avankest 1215: should prompt the end user for their username and
1.262 avankest 1216: password.</p>
1.295 avankest 1217:
1.311 avankest 1218: <p>Otherwise, if authentication fails, user agents
1.330 avankest 1219: must not prompt the end user for their username and
1220: password. <span data-anolis-ref>HTTPAUTH</span>
1.212 avankest 1221:
1.311 avankest 1222: <p class="note">End users are not prompted for various cases so that
1223: authors can implement their own user interface.</p>
1.295 avankest 1224:
1.262 avankest 1225: <hr>
1.212 avankest 1226:
1227: <p>If the user agent supports HTTP State Management it
1.330 avankest 1228: should persist, discard and send cookies (as received
1.297 avankest 1229: in the <code>Set-Cookie</code> response header, and sent in the
1230: <code>Cookie</code> header) as applicable.
1.330 avankest 1231: <span data-anolis-ref>COOKIES</span>
1.295 avankest 1232:
1.262 avankest 1233: <hr>
1.212 avankest 1234:
1.330 avankest 1235: <p>If the user agent implements a HTTP cache it should
1.352 avankest 1236: respect <code>Cache-Control</code> headers in
1237: <span>author request headers</span>
1238: (e.g. <code>Cache-Control: no-cache</code> bypasses the cache). It
1.330 avankest 1239: must not send <code>Cache-Control</code> or
1.279 avankest 1240: <code>Pragma</code> request headers automatically unless the end user
1241: explicitly requests such behavior (e.g. by reloading the page).</p>
1.212 avankest 1242:
1243: <p>For <code>304 Not Modified</code> responses that are a result of a
1244: user agent generated conditional request the user agent
1.330 avankest 1245: must act as if the server gave a <code>200 OK</code>
1.212 avankest 1246: response with the appropriate content. The user agent
1.352 avankest 1247: must allow <span>author request headers</span> to override automatic cache
1248: validation (e.g. <code>If-None-Match</code> or
1249: <code>If-Modified-Since</code>), in which case
1250: <code>304 Not Modified</code> responses must be passed through.
1251: <span data-anolis-ref>HTTP</span>
1.295 avankest 1252:
1.262 avankest 1253: <hr>
1.212 avankest 1254:
1255: <p>If the user agent implements server-driven content-negotiation
1.330 avankest 1256: it must follow these constraints for the
1.298 avankest 1257: <code>Accept</code> and <code>Accept-Language</code> request headers:</p>
1.231 avankest 1258:
1259: <ul>
1.352 avankest 1260: <li><p>Both headers must not be modified if they are in
1261: <span>author request headers</span>.
1262:
1263: <li><p>If not in <span>author request headers</span>,
1264: <code>Accept-Language</code> with an appropriate value should be appended
1265: to it.
1266:
1267: <li><p>If not in <span>author request headers</span>, <code>Accept</code>
1268: with value <code>*/*</code> must be appended to it.
1.231 avankest 1269: </ul>
1270:
1.330 avankest 1271: <p>Responses must have the content-encodings
1272: automatically decoded. <span data-anolis-ref>HTTP</span>
1.212 avankest 1273:
1.262 avankest 1274: <hr>
1275:
1.352 avankest 1276: <p>Besides the <span>author request headers</span>, user agents
1.330 avankest 1277: should not include additional request headers other than those mentioned
1278: above or other than those authors are not allowed to set using
1.279 avankest 1279: <code title="dom-XMLHttpRequest-setRequestHeader">setRequestHeader()</code>.
1.352 avankest 1280: This ensures that authors have a predictable API.</p>
1.218 avankest 1281:
1.212 avankest 1282:
1.330 avankest 1283: <h4>Infrastructure for the <code title>send()</code> method</h4>
1.216 avankest 1284:
1.219 avankest 1285: <p>The <dfn>same-origin request event rules</dfn> are as follows:</p>
1.118 avankest 1286:
1.203 avankest 1287: <dl class="switch">
1.316 avankest 1288: <dt>If the response has an HTTP status code of 301, 302, 303, or 307</dt>
1.203 avankest 1289: <dd>
1.300 avankest 1290: <p>If the redirect violates infinite loop precautions this is a
1291: <span>network error</span>.</p>
1292:
1293: <p>Otherwise, run these steps:</p>
1294:
1295: <ol>
1.330 avankest 1296: <li><p>Set the <span>request URL</span> to the
1297: <span data-anolis-spec=html>URL</span> conveyed by the
1298: <code>Location</code> header.</p></li>
1.300 avankest 1299:
1300: <li><p>If the <span><code>XMLHttpRequest</code> origin</span> and the
1.330 avankest 1301: <span data-anolis-spec=html>origin</span> of <span>request URL</span>
1302: are <span data-anolis-spec=html>same origin</span> transparently follow
1303: the redirect while observing the
1304: <span>same-origin request event rules</span>.
1.295 avankest 1305:
1.300 avankest 1306: <li><p>Otherwise, follow the <span>cross-origin request steps</span>
1307: and terminate the steps for this algorithm.</p></li>
1308: </ol>
1.203 avankest 1309:
1310: <p class="note">HTTP places requirements on the user agent regarding the
1.204 avankest 1311: preservation of the <span>request method</span> and
1.248 avankest 1312: <span>request entity body</span> during redirects, and also requires end
1313: users to be notified of certain kinds of automatic redirections.</p>
1.203 avankest 1314: <!-- XXX HTTP needs fixing here -->
1.213 avankest 1315: </dd>
1.121 avankest 1316:
1.285 avankest 1317: <dt>If the end user cancels the request</dt>
1.213 avankest 1318: <dd><p>This is an <span>abort error</span>.</p></dd>
1.60 avankest 1319:
1.285 avankest 1320: <dt>If there is a network error</dt>
1.213 avankest 1321: <dd>
1322: <p>In case of DNS errors, TLS negotiation failure, or other type of
1323: network errors, this is a <span>network error</span>. Do not request any
1.227 avankest 1324: kind of end user interaction.</p>
1.121 avankest 1325:
1.213 avankest 1326: <p class="note">This does not include HTTP responses that indicate
1327: some type of error, such as HTTP status code 410.</p>
1328: </dd>
1.60 avankest 1329:
1.248 avankest 1330:
1331:
1.306 avankest 1332: <dt>Once all HTTP headers have been received, the
1.348 avankest 1333: <span>synchronous flag</span> is unset, and the HTTP status code of the
1.316 avankest 1334: response is not 301, 302, 303, or 307</dt>
1.284 avankest 1335: <dd><p><span>Switch to the HEADERS_RECEIVED state</span>.</p></dd>
1.186 avankest 1336:
1.220 avankest 1337: <dt>Once the first byte (or more) of the
1338: <span>response entity body</span> has been received and the
1.348 avankest 1339: <span>synchronous flag</span> is unset</dt>
1.220 avankest 1340: <dt>If there is no <span>response entity body</span> and the
1.348 avankest 1341: <span>synchronous flag</span> is unset</dt>
1.284 avankest 1342: <dd><p><span>Switch to the LOADING state</span>.</p></dd>
1.295 avankest 1343:
1.220 avankest 1344: <dt>Once the whole <span>response entity body</span> has been
1345: received</dt>
1.296 avankest 1346: <dt>If there is no <span>response entity body</span> and the state is
1347: <span title="dom-XMLHttpRequest-LOADING">LOADING</span></dt>
1.224 avankest 1348: <dt>If there is no <span>response entity body</span> and the
1.348 avankest 1349: <span>synchronous flag</span> is set</dt>
1.284 avankest 1350: <dd><p><span>Switch to the DONE state</span>.</p></dd>
1.213 avankest 1351: </dl>
1.218 avankest 1352:
1.248 avankest 1353:
1354:
1.213 avankest 1355: <hr>
1.218 avankest 1356:
1.241 avankest 1357: <p>When something is said to be a <dfn>network error</dfn> run the
1358: <span>request error</span> steps for exception
1.343 avankest 1359: "<code data-anolis-spec=dom>NetworkError</code>".</p>
1.241 avankest 1360:
1361: <p>When something is said to be an <dfn>abort error</dfn> run the
1362: <span>request error</span> steps for exception
1.343 avankest 1363: "<code data-anolis-spec=dom>AbortError</code>".</p>
1.60 avankest 1364:
1.248 avankest 1365:
1366:
1.242 avankest 1367: <p>When something is said to be a <dfn>request error</dfn> for
1.248 avankest 1368: exception <var>exception</var> run these
1369: steps:</p>
1.12 avankest 1370:
1.213 avankest 1371: <ol>
1.330 avankest 1372: <li><p>The user agent should cancel any network
1.254 avankest 1373: activity for which the object is responsible.</p></li>
1374:
1.330 avankest 1375: <li><p>If there are any
1376: <span data-anolis-spec=html title=concept-task>tasks</span> from the
1377: object's <span><code>XMLHttpRequest</code> task source</span> in one of
1378: the <span data-anolis-spec=html title="task queue">task queues</span>,
1379: then remove them.
1.250 avankest 1380:
1.213 avankest 1381: <li><p>Set the the <span>error flag</span> to true.</p></li>
1.12 avankest 1382:
1.346 avankest 1383: <li><p>Change the state to <span title="dom-XMLHttpRequest-DONE">DONE</span>.</p></li>
1.203 avankest 1384:
1.348 avankest 1385: <li><p>If the <span>synchronous flag</span> is set,
1.342 avankest 1386: <span data-anolis-spec=dom title=concept-throw>throw</span> an
1.241 avankest 1387: <var>exception</var> exception and terminate the overall set of
1.213 avankest 1388: steps.</p></li>
1.203 avankest 1389:
1.248 avankest 1390: <li>
1.342 avankest 1391: <p><span data-anolis-spec=dom title=concept-event-fire>Fire an event</span> named <code title=event-xhr-readystatechange>readystatechange</code>.</p>
1.248 avankest 1392:
1393: <p class="note">At this point it is clear that the
1.348 avankest 1394: <span>synchronous flag</span> is unset.</p>
1.248 avankest 1395: </li>
1396:
1397:
1.213 avankest 1398: </ol>
1.203 avankest 1399:
1.248 avankest 1400:
1401: <p class="note">A future version of this specification will dispatch an
1.330 avankest 1402: <code title="event-xhr-error">error</code>/<code title="event-xhr-abort">abort</code>
1403: event here as well. (Depending on the type of error.)
1.248 avankest 1404:
1.203 avankest 1405:
1.213 avankest 1406: <hr>
1.203 avankest 1407:
1.213 avankest 1408: <p>When it is said to
1.284 avankest 1409: <dfn id="switch-headers-received">switch to the HEADERS_RECEIVED state</dfn>
1.213 avankest 1410: run these steps:</p>
1.203 avankest 1411:
1.213 avankest 1412: <ol>
1.346 avankest 1413: <li><p>Change the state to <span title="dom-XMLHttpRequest-HEADERS_RECEIVED">HEADERS_RECEIVED</span>.</p></li>
1.203 avankest 1414:
1.342 avankest 1415: <li><p><span data-anolis-spec=dom title=concept-event-fire>Fire an event</span> named <code title=event-xhr-readystatechange>readystatechange</code>.</p></li>
1.213 avankest 1416: </ol>
1.218 avankest 1417:
1.213 avankest 1418: <p>When it is said to
1.284 avankest 1419: <dfn id="switch-loading">switch to the LOADING state</dfn> run these
1.213 avankest 1420: steps:</p>
1.218 avankest 1421:
1.213 avankest 1422: <ol>
1.346 avankest 1423: <li><p>Change the state to <span title="dom-XMLHttpRequest-LOADING">LOADING</span>.</p></li>
1.203 avankest 1424:
1.342 avankest 1425: <li><p><span data-anolis-spec=dom title=concept-event-fire>Fire an event</span> named <code title=event-xhr-readystatechange>readystatechange</code>.</p></li>
1.213 avankest 1426: </ol>
1.218 avankest 1427:
1.216 avankest 1428: <p>When it is said to
1.284 avankest 1429: <dfn id="switch-done">switch to the DONE state</dfn> run these steps:</p>
1.218 avankest 1430:
1.216 avankest 1431: <ol>
1.348 avankest 1432: <li><p>If the <span>synchronous flag</span> is set, update the
1.255 avankest 1433: <span>response entity body</span>.</p></li>
1434:
1.346 avankest 1435: <li><p>Change the state to <span title="dom-XMLHttpRequest-DONE">DONE</span>.</p></li>
1.216 avankest 1436:
1.342 avankest 1437: <li><p><span data-anolis-spec=dom title=concept-event-fire>Fire an event</span> named <code title=event-xhr-readystatechange>readystatechange</code>.</p></li>
1.248 avankest 1438:
1.220 avankest 1439:
1.216 avankest 1440: </ol>
1.218 avankest 1441:
1.248 avankest 1442:
1443:
1.203 avankest 1444:
1.330 avankest 1445: <h4>The <code title>abort()</code> method</h4>
1.295 avankest 1446:
1.275 avankest 1447: <dl class="domintro">
1.330 avankest 1448: <dt><var title>client</var> . <code title="dom-XMLHttpRequest-abort">abort()</code></dt>
1.275 avankest 1449: <dd>Cancels any network activity.</dd>
1450: </dl>
1.203 avankest 1451:
1.351 avankest 1452: <p>The
1.331 avankest 1453: <dfn title="dom-XMLHttpRequest-abort"><code>abort()</code></dfn>
1.351 avankest 1454: method must run these steps (unless otherwise noted). This algorithm can
1455: be <dfn title="terminate abort()">terminated</dfn> by invoking the
1.314 avankest 1456: <code title="dom-XMLHttpRequest-open">open()</code> method. When it is
1457: <span title="terminate abort()">terminated</span> the user agent
1.351 avankest 1458: must terminate the algorithm after finishing the step it is on.
1.314 avankest 1459:
1460: <p class="note">The <code title="dom-XMLHttpRequest-abort">abort()</code>
1461: algorithm can only be terminated by invoking
1462: <code title="dom-XMLHttpRequest-open">open()</code> from an event
1463: handler.</p>
1.12 avankest 1464:
1.203 avankest 1465: <ol>
1.314 avankest 1466: <li><p><span title="terminate send()">Terminate the <code>send()</code> algorithm</span>.</p></li>
1.203 avankest 1467:
1.330 avankest 1468: <li><p>The user agent should cancel any network
1.203 avankest 1469: activity for which the object is responsible.</p></li>
1.252 avankest 1470:
1.330 avankest 1471: <li><p>If there are any
1472: <span data-anolis-spec=html title=concept-task>tasks</span> from the
1473: object's <span><code>XMLHttpRequest</code> task source</span> in one of
1474: the <span data-anolis-spec=html title="task queue">task queues</span>,
1475: then remove them.
1.203 avankest 1476:
1477: <li><p>Set the <span>error flag</span> to true.</p></li>
1478:
1479: <li>
1.272 avankest 1480: <p>If the state is <span title="dom-XMLHttpRequest-UNSENT">UNSENT</span>,
1481: <span title="dom-XMLHttpRequest-OPENED">OPENED</span> with the
1.203 avankest 1482: <span><code>send()</code> flag</span> being false, or
1.272 avankest 1483: <span title="dom-XMLHttpRequest-DONE">DONE</span> go to the next step.</p>
1.12 avankest 1484:
1.203 avankest 1485: <p>Otherwise run these substeps:</p>
1.58 avankest 1486:
1487: <ol>
1.346 avankest 1488: <li><p>Change the state to <span title="dom-XMLHttpRequest-DONE">DONE</span>.</p></li>
1.170 avankest 1489:
1.203 avankest 1490: <li><p>Set the <span><code>send()</code> flag</span> to false.</p></li>
1.96 avankest 1491:
1.342 avankest 1492: <li><p><span data-anolis-spec=dom title=concept-event-fire>Fire an event</span> named <code title=event-xhr-readystatechange>readystatechange</code>.</p></li>
1.248 avankest 1493:
1494:
1.58 avankest 1495: </ol>
1.250 avankest 1496:
1.248 avankest 1497:
1.250 avankest 1498: <p class="note">A future version of this specification will dispatch an
1.273 avankest 1499: <code title="event-xhr-abort">abort</code> event here.</p>
1.248 avankest 1500:
1.203 avankest 1501: </li>
1502:
1503: <li>
1.346 avankest 1504: <p>Change the state to <span title="dom-XMLHttpRequest-UNSENT">UNSENT</span>.</p>
1.203 avankest 1505:
1.273 avankest 1506: <p class="note">No <code title="event-xhr-readystatechange">readystatechange</code> event is dispatched.</p>
1.203 avankest 1507: </li>
1508: </ol>
1509:
1510:
1511:
1.205 avankest 1512: <h3 id="response">Response</h3>
1.203 avankest 1513:
1.330 avankest 1514: <h4>The <code title>status</code> attribute</h4>
1.203 avankest 1515:
1.276 avankest 1516: <dl class="domintro">
1.330 avankest 1517: <dt><var title>client</var> . <code title="dom-XMLHttpRequest-status">status</code></dt>
1.276 avankest 1518: <dd><p>Returns the HTTP status code.</p></dd>
1519: </dl>
1520:
1521: <p>The
1.331 avankest 1522: <dfn title="dom-XMLHttpRequest-status"><code>status</code></dfn>
1.330 avankest 1523: attribute must return the result of running these
1.276 avankest 1524: steps:</p>
1.226 avankest 1525:
1.222 avankest 1526: <ol>
1.272 avankest 1527: <li><p>If the state is <span title="dom-XMLHttpRequest-UNSENT">UNSENT</span> or
1528: <span title="dom-XMLHttpRequest-OPENED">OPENED</span> return 0 and terminate these
1.222 avankest 1529: steps.</p></li>
1530:
1.239 avankest 1531: <li><p>If the <span>error flag</span> is true return 0 and terminate
1532: these steps.</p></li>
1.295 avankest 1533:
1.222 avankest 1534: <li><p>Return the HTTP status code.</p></li>
1.295 avankest 1535: </ol>
1.203 avankest 1536:
1537:
1.330 avankest 1538: <h4>The <code title>statusText</code> attribute</h4>
1.203 avankest 1539:
1.276 avankest 1540: <dl class="domintro">
1.330 avankest 1541: <dt><var title>client</var> . <code title="dom-XMLHttpRequest-statusText">statusText</code></dt>
1.276 avankest 1542: <dd><p>Returns the HTTP status text.</p></dd>
1543: </dl>
1544:
1545: <p>The
1.331 avankest 1546: <dfn title="dom-XMLHttpRequest-statusText"><code>statusText</code></dfn>
1.330 avankest 1547: attribute must return the result of running these
1.276 avankest 1548: steps:</p>
1.295 avankest 1549:
1.222 avankest 1550: <ol>
1.272 avankest 1551: <li><p>If the state is <span title="dom-XMLHttpRequest-UNSENT">UNSENT</span> or
1552: <span title="dom-XMLHttpRequest-OPENED">OPENED</span> return the empty string and
1.239 avankest 1553: terminate these steps.</p></li>
1.222 avankest 1554:
1555: <li><p>If the <span>error flag</span> is true return the empty string and
1556: terminate these steps.</p></li>
1.295 avankest 1557:
1.222 avankest 1558: <li><p>Return the HTTP status text.</p></li>
1559: </ol>
1.203 avankest 1560:
1561:
1.330 avankest 1562: <h4>The <code title>getResponseHeader()</code> method</h4>
1.203 avankest 1563:
1.278 avankest 1564: <dl class="domintro">
1.330 avankest 1565: <dt><var title>client</var> . <code title="dom-XMLHttpRequest-getResponseHeader">getResponseHeader(<var title>header</var>)</code></dt>
1.278 avankest 1566: <dd><p>Returns the header field value from the response of which the
1.330 avankest 1567: field name matches <var title>header</var>, unless the field name is
1568: <code>Set-Cookie</code> or <code>Set-Cookie2</code>.</p>
1.278 avankest 1569: </dl>
1570:
1.351 avankest 1571: <p>The
1.331 avankest 1572: <dfn title="dom-XMLHttpRequest-getResponseHeader"><code>getResponseHeader(<var title>header</var>)</code></dfn>
1.351 avankest 1573: method must run these steps:
1.203 avankest 1574:
1575: <ol>
1.272 avankest 1576: <li><p>If the state is <span title="dom-XMLHttpRequest-UNSENT">UNSENT</span> or
1577: <span title="dom-XMLHttpRequest-OPENED">OPENED</span> return null and terminate these
1.203 avankest 1578: steps.</p></li>
1579:
1.239 avankest 1580: <li><p>If the <span>error flag</span> is true return null
1.203 avankest 1581: and terminate these steps.</p></li>
1582:
1.256 avankest 1583: <li><p>If any code point in <var>header</var> is higher than
1584: U+00FF LATIN SMALL LETTER Y WITH DIAERESIS return null and terminate
1585: these steps.</p></li>
1.295 avankest 1586:
1.256 avankest 1587: <li><p>Let <var>header</var> be the result of
1.294 avankest 1588: <span title="deflate a DOMString into a byte sequence">deflating</span>
1.256 avankest 1589: <var>header</var>.</p></li> <!-- This sounds lame, but it works. -->
1590:
1591: <li><p>If <var>header</var> is a case-insensitive match for
1592: <code>Set-Cookie</code> or <code>Set-Cookie2</code> return null and
1593: terminate these steps.</p></li>
1.203 avankest 1594:
1.256 avankest 1595: <li><p>If <var>header</var> is a case-insensitive match for multiple HTTP
1596: response headers, return the
1.294 avankest 1597: <span title="inflate a byte sequence into a DOMString">inflated</span>
1.256 avankest 1598: values of these headers as a single concatenated string separated from
1599: each other by a U+002C COMMA U+0020 SPACE character pair and terminate
1600: these steps.</p></li>
1.203 avankest 1601:
1.256 avankest 1602: <li><p>If <var>header</var> is a case-insensitive match for a single HTTP
1603: response header, return the
1.294 avankest 1604: <span title="inflate a byte sequence into a DOMString">inflated</span>
1.256 avankest 1605: value of that header and terminate these steps.</p></li>
1.203 avankest 1606:
1.239 avankest 1607: <li><p>Return null.</p></li>
1.203 avankest 1608: </ol>
1609:
1.248 avankest 1610:
1611:
1.203 avankest 1612: <div class="example">
1.295 avankest 1613:
1.250 avankest 1614: <p>For the following script:</p>
1615:
1616: <pre><code>var client = new XMLHttpRequest();
1617: client.open("GET", "unicorns-are-teh-awesome.txt", true);
1.5 avankest 1618: client.send();
1.12 avankest 1619: client.onreadystatechange = function() {
1.250 avankest 1620: if(this.readyState == 2) {
1621: print(client.getResponseHeader("Content-Type"));
1622: }
1623: }</code></pre>
1624:
1625: <p>The <code>print()</code> function will get to process something
1626: like:</p>
1.5 avankest 1627:
1.250 avankest 1628: <pre><code>text/plain; charset=UTF-8</code></pre>
1.203 avankest 1629: </div>
1.12 avankest 1630:
1631:
1.330 avankest 1632: <h4>The <code title>getAllResponseHeaders()</code> method</h4>
1.14 avankest 1633:
1.278 avankest 1634: <dl class="domintro">
1.330 avankest 1635: <dt><var title>client</var> . <code title="dom-XMLHttpRequest-getAllResponseHeaders">getAllResponseHeaders()</code></dt>
1.278 avankest 1636: <dd><p>Returns all headers from the response, with the exception of those
1637: whose field name is <code>Set-Cookie</code> or
1638: <code>Set-Cookie2</code>.</p></dd>
1639: </dl>
1640:
1.351 avankest 1641: <p>The
1.331 avankest 1642: <dfn title="dom-XMLHttpRequest-getAllResponseHeaders"><code>getAllResponseHeaders()</code></dfn>
1.351 avankest 1643: method must run these steps:</p>
1.58 avankest 1644:
1.203 avankest 1645: <ol>
1.272 avankest 1646: <li><p>If the state is <span title="dom-XMLHttpRequest-UNSENT">UNSENT</span> or
1647: <span title="dom-XMLHttpRequest-OPENED">OPENED</span> return the empty string and
1.239 avankest 1648: terminate these steps.</p></li>
1.203 avankest 1649:
1650: <li><p>If the <span>error flag</span> is true return the empty string and
1651: terminate these steps.</p></li>
1652:
1.256 avankest 1653: <li><p>Return all the HTTP headers, excluding headers that are a
1654: case-insensitive match for <code>Set-Cookie</code> or
1655: <code>Set-Cookie2</code>,
1.294 avankest 1656: <span title="inflate a byte sequence into a DOMString">inflated</span>,
1.256 avankest 1657: as a single string, with each header line
1658: separated by a U+000D CR U+000A LF pair, excluding the status line, and
1.203 avankest 1659: with each header name and header value separated by a
1660: U+003A COLON U+0020 SPACE pair.</p></li>
1661: </ol>
1.58 avankest 1662:
1.250 avankest 1663:
1664:
1.203 avankest 1665: <div class="example">
1.250 avankest 1666: <p>For the following script:</p>
1.295 avankest 1667:
1.250 avankest 1668: <pre><code>var client = new XMLHttpRequest();
1669: client.open("GET", "narwhals-too.txt", true);
1.5 avankest 1670: client.send();
1.12 avankest 1671: client.onreadystatechange = function() {
1.308 avankest 1672: if(this.readyState == 2) {
1673: print(this.getAllResponseHeaders());
1674: }
1.250 avankest 1675: }</code></pre>
1676:
1677: <p>The <code>print()</code> function will get to process something
1678: like:</p>
1.1 avankest 1679:
1.250 avankest 1680: <pre><code>Date: 2004年10月24日 04:58:38 GMT
1.203 avankest 1681: Server: Apache/1.3.31 (Unix)
1682: Keep-Alive: timeout=15, max=99
1683: Connection: Keep-Alive
1684: Transfer-Encoding: chunked
1685: Content-Type: text/plain; charset=utf-8</code></pre>
1686: </div>
1687:
1.250 avankest 1688:
1.203 avankest 1689:
1.334 avankest 1690: <h4>Response entity body</h4>
1.203 avankest 1691:
1.248 avankest 1692: <p>The <dfn id="response-mime-type">response MIME type</dfn> is the MIME
1693: type the <code>Content-Type</code> header contains without any
1694: parameters or null if the header could not be parsed properly or was
1695: omitted. The <dfn id="override-mime-type">override MIME type</dfn> is
1696: always null. <dfn id="final-mime-type">Final MIME type</dfn> is the
1697: override MIME type unless that is null in which case it is the response
1698: MIME type.</p>
1699:
1700: <p>The <dfn id="response-charset">response charset</dfn> is the value of
1701: the <code>charset</code> parameter of the <code>Content-Type</code> header
1702: or null if there was no <code>charset</code> parameter or if
1703: the header could not be parsed properly or was omitted. The
1704: <dfn id="override-charset">override charset</dfn> is always null.
1705: <dfn id="final-charset">Final charset</dfn> is the override charset unless
1706: that is null in which case it is the response charset.</p>
1.250 avankest 1707:
1.248 avankest 1708:
1709: <p class="note"><span>Override MIME type</span> and
1710: <span>override charset</span> are introduced here solely to make editing
1711: several levels of XMLHttpRequest simultaneously somewhat easier. Apologies
1712: for any confusion they might cause.</p>
1713:
1.250 avankest 1714:
1.248 avankest 1715: <hr>
1716:
1.203 avankest 1717: <p>The <dfn id="response-entity-body">response entity body</dfn> is the
1.330 avankest 1718: fragment of the <span data-anolis-spec=http>entity body</span> of the
1719: response received so far
1720: (<span title="dom-XMLHttpRequest-LOADING">LOADING</span>) or the complete
1721: entity body of the response
1722: (<span title="dom-XMLHttpRequest-DONE">DONE</span>). If the response
1.255 avankest 1723: does not have an entity body the response entity body is null.</p>
1724:
1725: <p class="note">The <span>response entity body</span> is updated as part
1.271 avankest 1726: of the <code title="dom-XMLHttpRequest-send">send()</code> algorithm.</p>
1.250 avankest 1727:
1.203 avankest 1728: <hr>
1729:
1730: <p>The <dfn id="text-response-entity-body">text response entity body</dfn>
1.248 avankest 1731: is a <code>DOMString</code> representing the <span>response entity
1732: body</span>. The text response entity body is the return value of the
1.203 avankest 1733: following algorithm:</p>
1734:
1735: <ol>
1.248 avankest 1736: <li><p>If the response entity body is null return the empty string and
1737: terminate these steps.</p>
1738:
1739: <li><p>Let <var>charset</var> be the <span>final charset</span>.</p></li>
1.203 avankest 1740:
1.248 avankest 1741: <li><p>Let <var>mime</var> be the <span>final MIME type</span>.</p></li>
1.203 avankest 1742:
1.248 avankest 1743: <li><p>If <var>charset</var> is null and <var>mime</var> is null,
1.203 avankest 1744: <code>text/xml</code>, <code>application/xml</code> or ends in
1.330 avankest 1745: <code title>+xml</code> use the rules set forth in the XML
1.248 avankest 1746: specifications to determine the character encoding. Let
1747: <var>charset</var> be the determined character encoding.</p></li>
1748:
1749: <li><p>If <var>charset</var> is null and <var>mime</var> is
1750: <code>text/html</code> follow the rules set forth in the HTML
1751: specification to determine the character encoding. Let
1.203 avankest 1752: <var>charset</var> be the determined character encoding.
1.330 avankest 1753: <span data-anolis-ref>HTML</span>
1.203 avankest 1754:
1755: <li>
1756: <p>If <var>charset</var> is null then, for each of the rows in the
1757: following table, starting with the first one and going down, if the first
1758: bytes of <var>bytes</var> match the bytes given in the first column, then
1759: let <var>charset</var> be the encoding given in the cell in the second
1760: column of that row. If there is no match <var>charset</var> remains
1761: null.</p>
1762:
1763: <table>
1764: <thead>
1765: <tr>
1766: <th>Bytes in Hexadecimal
1767: <th>Description
1.237 avankest 1768: <tbody>
1.203 avankest 1769: <tr>
1770: <td>FE FF
1771: <td>UTF-16BE BOM
1772: <tr>
1773: <td>FF FE
1774: <td>UTF-16LE BOM
1775: <tr>
1776: <td>EF BB BF
1.237 avankest 1777: <td>UTF-8 BOM
1.203 avankest 1778: </table>
1779: </li>
1780:
1781: <li><p>If <var>charset</var> is null let <var>charset</var> be
1782: UTF-8.</p></li>
1783:
1784: <li><p>Return the result of decoding the response entity body using
1785: <var>charset</var>. Replace bytes or sequences of bytes that are not
1.248 avankest 1786: valid accordng to the <var>charset</var> with a single
1.315 avankest 1787: U+FFFD REPLACEMENT CHARACTER character. Remove one leading
1788: U+FEFF BYTE ORDER MARK character, if present.</p></li>
1.203 avankest 1789: </ol>
1790:
1.315 avankest 1791: <p class="note">Authors are strongly encouraged to always encode their
1792: resources using UTF-8.</p>
1.295 avankest 1793:
1.203 avankest 1794: <hr>
1795:
1.248 avankest 1796: <p>The <dfn id="document-response-entity-body">document response entity
1.342 avankest 1797: body</dfn> is either a <code data-anolis-spec=dom>Document</code> representing the
1.320 avankest 1798: <span>response entity body</span> or null. If it is a
1.342 avankest 1799: <code data-anolis-spec=dom>Document</code> its <span data-anolis-spec=html>origin</span> is the
1.320 avankest 1800: <span><code>XMLHttpRequest</code> origin</span>. If the
1.317 avankest 1801: <span>document response entity body</span> has no value assigned to it let
1802: it be the return value of the following algorithm:</p>
1.12 avankest 1803:
1.203 avankest 1804: <ol>
1.309 avankest 1805: <li><p>If the <span>response entity body</span> is null, return null and
1806: terminate these steps.</p></li>
1.12 avankest 1807:
1.248 avankest 1808: <li><p>If <span>final MIME type</span> is not null,
1809: <code>text/xml</code>,
1.295 avankest 1810: <code>application/xml</code>, or does not end in
1.330 avankest 1811: <code title>+xml</code>, return null and terminate these
1.309 avankest 1812: steps.</p></li>
1.248 avankest 1813:
1814:
1.203 avankest 1815:
1816: <li>
1.330 avankest 1817: <p>Let <var title>document</var> be a
1.342 avankest 1818: <code data-anolis-spec=dom>Document</code> object that represents the result of parsing the
1.319 avankest 1819: <span>response entity body</span> into a document tree following the
1820: rules set forth in the XML specifications. If that fails
1.265 avankest 1821: (unsupported character encoding, namespace well-formedness error et
1.309 avankest 1822: cetera) return null and terminate these steps.
1.330 avankest 1823: <span data-anolis-ref>XML</span> <span data-anolis-ref>XMLNS</span>
1.248 avankest 1824:
1825: <p class="note">Scripts in the resulting document tree will not be executed,
1826: resources referenced will not be loaded and no associated XSLT will be
1.319 avankest 1827: applied.</p> <!-- XXX more formally?! -->
1.203 avankest 1828: </li>
1.88 avankest 1829:
1.330 avankest 1830: <li><p>Return <var title>document</var>.</p></li>
1.203 avankest 1831: </ol>
1.12 avankest 1832:
1.248 avankest 1833:
1834:
1835:
1.330 avankest 1836: <h4>The <code title>responseText</code> attribute</h4>
1.12 avankest 1837:
1.276 avankest 1838: <dl class="domintro">
1.330 avankest 1839: <dt><var title>client</var> . <code title="dom-XMLHttpRequest-responseText">responseText</code></dt>
1.305 avankest 1840: <dd>
1841: <p>Returns the <span>text response entity body</span>.</p>
1842:
1843: </dd>
1.276 avankest 1844: </dl>
1845:
1846: <p>The
1.331 avankest 1847: <dfn title="dom-XMLHttpRequest-responseText"><code>responseText</code></dfn>
1.330 avankest 1848: attribute must return the result of running these
1.276 avankest 1849: steps:</p>
1.79 avankest 1850:
1.203 avankest 1851: <ol>
1.305 avankest 1852:
1853:
1.272 avankest 1854: <li><p>If the state is not <span title="dom-XMLHttpRequest-LOADING">LOADING</span> or
1855: <span title="dom-XMLHttpRequest-DONE">DONE</span> return the empty string and
1.203 avankest 1856: terminate these steps.</p></li>
1.75 avankest 1857:
1.313 avankest 1858: <li><p>If the <span>error flag</span> is true return the empty string and
1859: terminate these steps.</p></li>
1860:
1.203 avankest 1861: <li><p>Return the <span>text response entity body</span>.</p></li>
1862: </ol>
1.12 avankest 1863:
1864:
1.330 avankest 1865: <h4>The <code title>responseXML</code> attribute</h4>
1.12 avankest 1866:
1.276 avankest 1867: <dl class="domintro">
1.330 avankest 1868: <dt><var title>client</var> . <code title="dom-XMLHttpRequest-responseXML">responseXML</code></dt>
1.305 avankest 1869: <dd>
1870: <p>Returns the <span>document response entity body</span>.</p>
1871:
1872: </dd>
1.276 avankest 1873: </dl>
1874:
1875: <p>The
1.331 avankest 1876: <dfn title="dom-XMLHttpRequest-responseXML"><code>responseXML</code></dfn>
1877: attribute must return the result of running these steps:</p>
1.12 avankest 1878:
1.203 avankest 1879: <ol>
1.305 avankest 1880:
1881:
1.272 avankest 1882: <li><p>If the state is not <span title="dom-XMLHttpRequest-DONE">DONE</span> return
1.239 avankest 1883: null and terminate these steps.</p></li>
1.12 avankest 1884:
1.313 avankest 1885: <li><p>If the <span>error flag</span> is true return null and terminate
1886: these steps.</p></li>
1887:
1.317 avankest 1888: <li><p>Return the <span>document response entity body</span>.</p></li>
1.203 avankest 1889: </ol>
1.121 avankest 1890:
1.248 avankest 1891:
1892:
1.12 avankest 1893:
1.330 avankest 1894: <h2 class=no-num>References</h2>
1895: <h3 class=no-num>Normative references</h3>
1896: <div id=anolis-references-normative></div>
1.248 avankest 1897:
1.330 avankest 1898: <h3 class=no-num>Informative references</h3>
1899: <div id=anolis-references-informative></div>
1.11 avankest 1900:
1.203 avankest 1901:
1902:
1.130 avankest 1903: <h2 class="no-num" id="acknowledgments">Acknowledgments</h2>
1.11 avankest 1904:
1.159 avankest 1905: <p>The editor would like to thank
1.12 avankest 1906:
1.163 avankest 1907: Addison Phillips,
1.159 avankest 1908: Ahmed Kamel,
1909: Alex Hopmann,
1910: Alex Vincent,
1911: Alexey Proskuryakov,
1912: Asbjørn Ulsberg,
1913: Boris Zbarsky,
1914: Björn Höhrmann,
1915: Cameron McCormack,
1.321 avankest 1916: Chris Marrin,
1.159 avankest 1917: Christophe Jolif,
1918: Charles McCathieNevile,
1919: Dan Winship,
1.248 avankest 1920: David Andersson,
1.321 avankest 1921: David Flanagan,
1.159 avankest 1922: David Håsäther,
1.248 avankest 1923: David Levin,
1.159 avankest 1924: Dean Jackson,
1925: Denis Sureau,
1926: Doug Schepers,
1927: Douglas Livingstone,
1928: Elliotte Harold,
1929: Eric Lawrence,
1.321 avankest 1930: Eric Uhrhane,
1.196 avankest 1931: Erik Dahlström,
1.163 avankest 1932: Geoffrey Sneddon,
1.159 avankest 1933: Gideon Cohn,
1934: Gorm Haug Eriksen,
1.247 avankest 1935: Håkon Wium Lie,
1.159 avankest 1936: Hallvord R. M. Steen,
1.328 avankest 1937: Henri Sivonen,
1.247 avankest 1938: Huub Schaeks,
1.159 avankest 1939: Ian Davis,
1940: Ian Hickson,
1941: Ivan Herman,
1942: Jeff Walden,
1943: Jens Lindström,
1944: Jim Deegan,
1945: Jim Ley,
1946: Joe Farro,
1947: Jonas Sicking,
1948: Julian Reschke,
1949: Karl Dubost,
1.175 avankest 1950: Lachlan Hunt,
1.159 avankest 1951: Maciej Stachowiak,
1952: Magnus Kristiansen,
1953: Marc Hadley,
1954: Marcos Caceres,
1955: Mark Baker,
1.203 avankest 1956: Mark Birbeck,
1.159 avankest 1957: Mark Nottingham,
1.267 avankest 1958: Mark S. Miller,
1.248 avankest 1959: Martin Hassman,
1.159 avankest 1960: Mohamed Zergaoui,
1.345 avankest 1961: Ms2ger,
1.346 avankest 1962: Odin Hørthe Omdal,
1.256 avankest 1963: Olli Pettay,
1.159 avankest 1964: Pawel Glowacki,
1.231 avankest 1965: Peter Michaux,
1.264 avankest 1966: Philip Taylor,
1.159 avankest 1967: Robin Berjon,
1.248 avankest 1968: Rune Halvorsen,
1.159 avankest 1969: Ruud Steltenpool,
1.310 avankest 1970: Sergiu Dumitriu,
1.346 avankest 1971: Sigbjørn Finne,
1.159 avankest 1972: Simon Pieters,
1973: Stewart Brodie,
1974: Sunava Dutta,
1.186 avankest 1975: Thomas Roessler,
1.203 avankest 1976: Tom Magliery, and
1.159 avankest 1977: Zhenbin Xu
1.181 avankest 1978:
1.159 avankest 1979: for their contributions to this specification.</p>
1.12 avankest 1980:
1.1 avankest 1981: <p>Special thanks to the Microsoft employees who first implemented the
1.330 avankest 1982: <code title>XMLHttpRequest</code> interface, which was first widely
1.143 avankest 1983: deployed by the Windows Internet Explorer browser.</p>
1.12 avankest 1984:
1.143 avankest 1985: <p>Special thanks also to the WHATWG for drafting an initial version of
1986: this specification in their Web Applications 1.0 document (now renamed to
1.330 avankest 1987: HTML). <span data-anolis-ref>HTML</span></p>
1.12 avankest 1988:
1.143 avankest 1989: <p>Thanks also to all those who have helped to improve this specification
1990: by sending suggestions and corrections. (Please, keep bugging us with your
1.22 avankest 1991: issues!)</p>
1.1 avankest 1992: </body>
1993: </html>
Webmaster