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