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