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