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