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