Annotation of 2006/webapi/XMLHttpRequest/Overview.html, revision 1.366
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.366 ! avankest 42: <h2 class="no-num no-toc" id="w3c-doctype">Editor's Draft 18 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.366 ! avankest 93: <p>This is the 18 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.365 avankest 454: <h3 id="task-sources"><span class="secno">4.2 </span>Task sources</h3>
1.205 avankest 455:
1.365 avankest 456: <p>Each <code><a href="#xmlhttprequest">XMLHttpRequest</a></code> object has its own
457: <a class="external" href="http://www.whatwg.org/specs/web-apps/current-work/multipage/webappapis.html#task-source">task source</a>. Namely, the
458: <dfn id="xmlhttprequest-task-source"><code>XMLHttpRequest</code> task source</dfn>.
1.282 avankest 459:
460:
1.343 avankest 461: <h3 id="constructors"><span class="secno">4.3 </span>Constructors</h3>
1.205 avankest 462:
1.343 avankest 463:
1.125 avankest 464:
1.343 avankest 465: <dl class="domintro">
466: <dt><var title="">client</var> = new <code title="dom-XMLHttpRequest"><a href="#dom-xmlhttprequest">XMLHttpRequest</a></code>()</dt>
467: <dd>Returns a new <code><a href="#xmlhttprequest">XMLHttpRequest</a></code> object.</dd>
468:
469: </dl>
1.205 avankest 470:
1.366 ! avankest 471: <p>The <dfn id="dom-xmlhttprequest" title="dom-XMLHttpRequest"><code>XMLHttpRequest()</code></dfn>
! 472: constructor must return a new <code><a href="#xmlhttprequest">XMLHttpRequest</a></code> object.
1.343 avankest 473:
474:
475:
1.350 avankest 476:
477:
478: <h3 id="garbage-collection"><span class="secno">4.4 </span>Garbage collection</h3>
479:
480: <!-- Based on EventSource and WebSocket. Not sure what I am doing. -->
481:
482: <p>An <code><a href="#xmlhttprequest">XMLHttpRequest</a></code> object must not be garbage collected if
1.355 avankest 483: its state is <a href="#dom-xmlhttprequest-opened" title="dom-XMLHttpRequest-OPENED">OPENED</a> and the
484: <a href="#send-flag"><code>send()</code> flag</a> is set, its state is
485: <a href="#dom-xmlhttprequest-headers_received" title="dom-XMLHttpRequest-HEADERS_RECEIVED">HEADERS_RECEIVED</a>, or
486: its state is <a href="#dom-xmlhttprequest-loading" title="dom-XMLHttpRequest-LOADING">LOADING</a>, and
487: it has one or more
1.350 avankest 488: <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>
489: registered whose <b>type</b> is
1.351 avankest 490: <code title="event-xhr-readystatechange">readystatechange</code>.
1.350 avankest 491:
492: <p>If an <code><a href="#xmlhttprequest">XMLHttpRequest</a></code> object is garbage collected while its
493: connection is still open, the user agent must cancel any instance of the
494: <a class="external" href="http://www.whatwg.org/specs/web-apps/current-work/multipage/urls.html#fetch">fetch</a> algorithm opened by this object,
495: 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>
496: <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
497: discarding any further data received from the network for them.
498:
499:
500:
501: <h3 id="event-handlers"><span class="secno">4.5 </span>Event handlers</h3>
1.343 avankest 502:
503:
504:
505: <p>The following is the
1.346 avankest 506: <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 507: (and its corresponding
1.346 avankest 508: <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 509: supported as attribute by the
1.343 avankest 510: <code><a href="#xmlhttprequest">XMLHttpRequest</a></code> object:</p>
1.205 avankest 511:
1.343 avankest 512: <table>
513: <thead>
514: <tr>
1.346 avankest 515: <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>
516: <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 517: <tbody>
518: <tr>
519: <td><dfn id="handler-xhr-onreadystatechange" title="handler-xhr-onreadystatechange"><code>onreadystatechange</code></dfn>
520: <td><code title="event-xhr-readystatechange">readystatechange</code></td>
521: </table>
1.89 avankest 522:
1.112 avankest 523:
1.350 avankest 524: <h3 id="states"><span class="secno">4.6 </span>States</h3>
1.91 avankest 525:
1.343 avankest 526: <dl class="domintro">
527: <dt><var title="">client</var> . <code title="dom-XMLHttpRequest-readyState"><a href="#dom-xmlhttprequest-readystate">readyState</a></code></dt>
528: <dd><p>Returns the current state.</dd>
1.205 avankest 529: </dl>
1.116 avankest 530:
1.343 avankest 531: <p>The <code><a href="#xmlhttprequest">XMLHttpRequest</a></code> object can be in several states. The
532: <dfn id="dom-xmlhttprequest-readystate" title="dom-XMLHttpRequest-readyState"><code>readyState</code></dfn>
1.345 avankest 533: attribute must return the current state, which must be one of the
534: following values:</p>
1.112 avankest 535:
1.206 avankest 536: <dl>
1.343 avankest 537: <dt><dfn id="dom-xmlhttprequest-unsent" title="dom-XMLHttpRequest-UNSENT"><code>UNSENT</code></dfn>
538: (numeric value 0)</dt>
539: <dd><p>The object has been constructed.</dd>
540:
541: <dt><dfn id="dom-xmlhttprequest-opened" title="dom-XMLHttpRequest-OPENED"><code>OPENED</code></dfn>
542: (numeric value 1)</dt>
543: <dd><p>The <code title="dom-XMLHttpRequest-open"><a href="#dom-xmlhttprequest-open">open()</a></code> method has been successfully invoked.
544: During this state request headers can be set using
545: <code title="dom-XMLHttpRequest-setRequestHeader"><a href="#dom-xmlhttprequest-setrequestheader">setRequestHeader()</a></code>
546: and the request can be made using the
547: <code title="dom-XMLHttpRequest-send"><a href="#dom-xmlhttprequest-send">send()</a></code> method.</dd>
548:
549: <dt><dfn id="dom-xmlhttprequest-headers_received" title="dom-XMLHttpRequest-HEADERS_RECEIVED"><code>HEADERS_RECEIVED</code></dfn>
550: (numeric value 2)</dt>
551: <dd><p>All redirects (if any) have been followed and all HTTP headers of
552: the final response have been received. Several response members of the
553: object are now available.</dd>
554:
555: <dt><dfn id="dom-xmlhttprequest-loading" title="dom-XMLHttpRequest-LOADING"><code>LOADING</code></dfn>
556: (numeric value 3)</dt>
557: <dd><p>The <a href="#response-entity-body">response entity body</a> is being received.</dd>
558:
559: <dt><dfn id="dom-xmlhttprequest-done" title="dom-XMLHttpRequest-DONE"><code>DONE</code></dfn>
560: (numeric value 4)</dt>
561: <dd><p>The data transfer has been completed or something went wrong
562: during the transfer (e.g. infinite redirects).</dd>
563: </dl>
1.342 avankest 564:
1.343 avankest 565: <p>The <a href="#dom-xmlhttprequest-opened" title="dom-XMLHttpRequest-OPENED">OPENED</a> state has an associated
566: <dfn id="send-flag"><code>send()</code> flag</dfn> that indicates whether
567: the <code title="dom-XMLHttpRequest-send"><a href="#dom-xmlhttprequest-send">send()</a></code> method has been
568: invoked. It can be either true or false and has an initial value of
569: false.</p>
570:
571: <p>The <dfn id="error-flag">error flag</dfn> indicates some type of
572: network error or abortion. It is used during the
573: <a href="#dom-xmlhttprequest-done" title="dom-XMLHttpRequest-DONE">DONE</a> state. It can be either
574: true or false and has an initial value of false.</p>
1.342 avankest 575:
576:
1.350 avankest 577: <h3 id="request"><span class="secno">4.7 </span>Request</h3>
1.342 avankest 578:
1.343 avankest 579: <p>The <code><a href="#xmlhttprequest">XMLHttpRequest</a></code> object holds the following request
580: metadata variables:</p>
1.342 avankest 581:
1.343 avankest 582: <dl>
1.363 avankest 583: <dt>The <dfn id="synchronous-flag">synchronous flag</dfn></dt>
584: <dd>Set when <a class="external" href="http://www.whatwg.org/specs/web-apps/current-work/multipage/urls.html#fetch" title="fetch">fetching</a> is
585: done synchronously. Initially unset.</dd>
1.343 avankest 586:
587: <dt>The <dfn id="request-method">request method</dfn></dt>
588: <dd>The HTTP method used in the request.</dd>
589:
590: <dt>The <dfn id="request-url">request URL</dfn></dt>
1.346 avankest 591: <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 592: request.</dd>
593:
594: <dt>The <dfn id="request-username">request username</dfn></dt>
595: <dd>The username used in the request or null if there is no
596: username.</dd>
597:
598: <dt>The <dfn id="request-password">request password</dfn></dt>
599: <dd>The password used in the request or null if there is no
600: password.</dd>
1.206 avankest 601:
1.343 avankest 602: <dt>The <dfn id="author-request-headers">author request headers</dfn></dt>
603: <dd>A list consisting of HTTP header name/value pairs to be used in the
604: request.<p></p>
1.206 avankest 605:
1.343 avankest 606: <dt>The <dfn id="request-entity-body">request entity body</dfn></dt>
607: <dd>The <a class="external" href="http://tools.ietf.org/html/rfc2616/#section-7.2">entity body</a> used in the
608: request or null if there is no
609: <a class="external" href="http://tools.ietf.org/html/rfc2616/#section-7.2">entity body</a>.</dd>
1.206 avankest 610:
1.343 avankest 611:
612: </dl>
1.206 avankest 613:
1.343 avankest 614:
1.206 avankest 615:
616:
1.350 avankest 617: <h4 id="the-open-method"><span class="secno">4.7.1 </span>The <code title="">open()</code> method</h4>
1.206 avankest 618:
1.343 avankest 619: <dl class="domintro">
620: <dt><var title="">client</var> . <code title="dom-XMLHttpRequest-open"><a href="#dom-xmlhttprequest-open">open(<var title="">method</var>,
621: <var title="">url</var>, <var title="">async</var>, <var title="">user</var>,
622: <var title="">password</var>)</a></code></dt>
1.206 avankest 623:
1.343 avankest 624: <dd>
625: <p>Sets the <a href="#request-method">request method</a>, <a href="#request-url">request URL</a>,
1.363 avankest 626: <a href="#synchronous-flag">synchronous flag</a>, <a href="#request-username">request username</a>, and
1.343 avankest 627: <a href="#request-password">request password</a>.</p>
1.206 avankest 628:
1.357 avankest 629: <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
630: one of the following is true:</p>
1.112 avankest 631:
1.342 avankest 632: <ul>
1.343 avankest 633: <li><var title="">method</var> is not a valid HTTP method.</li>
634: <li><var title="">url</var> cannot be resolved.</li>
635: <li><var title="">url</var> contains the <code>"user:password"</code>
636: 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 637: </ul>
638:
1.357 avankest 639: <p>Throws a "<code class="external"><a href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#securityerror">SecurityError</a></code>" exception
640: if <var title="">method</var> is a case-insensitive match for
1.343 avankest 641: <code>CONNECT</code>, <code>TRACE</code> or <code>TRACK</code>.</p>
642:
1.357 avankest 643: <p>Throws an "<code class="external"><a href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#invalidaccesserror">InvalidAccessError</a></code>"
1.366 ! avankest 644: exception if one of the following is true:</p>
! 645:
! 646: <ul>
! 647: <li>Either <var title="">user</var> or <var title="">password</var> is passed
! 648: as argument and the <a class="external" href="http://www.whatwg.org/specs/web-apps/current-work/multipage/origin-0.html#origin">origin</a> of
! 649: <var title="">url</var> does not match the
! 650: <a href="#xmlhttprequest-origin"><code>XMLHttpRequest</code> origin</a>.
! 651: <li>There is an associated
! 652: <a href="#xmlhttprequest-document"><code>XMLHttpRequest</code> document</a> and either the
! 653: <code title="dom-XMLHttpRequest-timeout">timeout</code> attribute is not
! 654: zero, the
! 655: <code title="dom-XMLHttpRequest-withCredentials">withCredentials</code>
! 656: attribute is true, or the
! 657: <code title="dom-XMLHttpRequest-responseType">responseType</code>
! 658: attribute is not the empty string.
! 659: </ul>
1.343 avankest 660: </dd>
1.274 avankest 661: </dl>
662:
1.366 ! avankest 663: <p>The
1.343 avankest 664: <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>
1.366 ! avankest 665: method must run these steps (unless otherwise indicated):</p>
1.112 avankest 666:
1.205 avankest 667: <ol>
668: <li>
1.364 avankest 669: <p>If there is an associated
1.349 avankest 670: <a href="#xmlhttprequest-document"><code>XMLHttpRequest</code> document</a> run
1.343 avankest 671: these substeps:</p>
1.112 avankest 672:
1.205 avankest 673: <ol>
1.343 avankest 674: <li><p>If the
1.349 avankest 675: <a href="#xmlhttprequest-document"><code>XMLHttpRequest</code> document</a> is not
1.356 avankest 676: <a class="external" href="http://www.whatwg.org/specs/web-apps/current-work/multipage/browsers.html#fully-active">fully active</a>,
677: <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 678: "<code class="external"><a href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#invalidstateerror">InvalidStateError</a></code>" exception and
679: terminate the overall set of steps.
1.343 avankest 680:
681: <li><p>Let <a href="#xmlhttprequest-base-url"><code>XMLHttpRequest</code> base URL</a> be the
1.346 avankest 682: <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 683: <a href="#xmlhttprequest-document"><code>XMLHttpRequest</code> document</a>.</li>
1.343 avankest 684:
685: <li><p>Let <a href="#xmlhttprequest-origin"><code>XMLHttpRequest</code> origin</a> be the
1.346 avankest 686: <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 687: <a href="#xmlhttprequest-document"><code>XMLHttpRequest</code> document</a>.</li>
1.205 avankest 688: </ol>
1.343 avankest 689: </li>
1.342 avankest 690:
1.343 avankest 691: <li><p>If any code point in <var>method</var> is higher than
692: U+00FF LATIN SMALL LETTER Y WITH DIAERESIS or after
693: <a href="#deflate-a-domstring-into-a-byte-sequence" title="deflate a DOMString into a byte sequence">deflating</a>
694: <var>method</var> it does not match the
1.356 avankest 695: <a class="external" href="http://tools.ietf.org/html/rfc2616/#section-5.1.1">Method</a> token production,
696: <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 697: "<code class="external"><a href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#syntaxerror">SyntaxError</a></code>" exception and terminate
698: these steps. Otherwise let <var>method</var> be the result of
1.343 avankest 699: <a href="#deflate-a-domstring-into-a-byte-sequence" title="deflate a DOMString into a byte sequence">deflating</a>
700: <var>method</var>.</li> <!-- This sounds lame, but it works. -->
1.91 avankest 701:
702: <li>
1.258 avankest 703: <p>If <var>method</var> is a case-insensitive match for
1.343 avankest 704: <code>CONNECT</code>, <code>DELETE</code>, <code>GET</code>,
705: <code>HEAD</code>, <code>OPTIONS</code>, <code>POST</code>,
706: <code>PUT</code>, <code>TRACE</code>, or <code>TRACK</code>
707: subtract 0x20 from each byte in the range 0x61 (ASCII a) to
708: 0x7A (ASCII z).</p>
1.205 avankest 709:
1.343 avankest 710: <p class="note">If it does not match any of the above, it is passed
711: through <em>literally</em>, including in the final request.</p>
1.205 avankest 712: </li>
713: <!-- WebKit (and supposedly Gecko) also uppercase: COPY, INDEX, LOCK,
714: M-POST, MKCOL, MOVE, PROPFIND, PROPPATCH, and UNLOCK. -->
1.89 avankest 715:
1.205 avankest 716: <li>
1.258 avankest 717: <p>If <var>method</var> is a case-sensitive match for
1.356 avankest 718: <code>CONNECT</code>, <code>TRACE</code>, or <code>TRACK</code>,
719: <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 720: "<code class="external"><a href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#securityerror">SecurityError</a></code>" exception and
721: terminate these steps.
1.164 avankest 722:
1.343 avankest 723: <p class="note">Allowing these methods poses a security risk.
724: <a href="#refsHTTPVERBSEC">[HTTPVERBSEC]</a>
725: </li>
726:
727: <li><p>Let <var title="">url</var> be a
1.346 avankest 728: <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 729:
1.343 avankest 730: <li><p><span title="Resolve a URL">Resolve</span> <var title="">url</var>
731: relative to the <a href="#xmlhttprequest-base-url"><code>XMLHttpRequest</code> base URL</a>.
1.356 avankest 732: If the algorithm returns an error,
733: <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 734: "<code class="external"><a href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#syntaxerror">SyntaxError</a></code>" exception and terminate
735: these steps.
1.89 avankest 736:
1.205 avankest 737: <!-- Presto and Gecko override the encoding. WebKit does not. Trident
738: does not support non-ASCII URLs. This matters for the <query> component,
1.330 avankest 739: see HTML. -->
1.129 avankest 740:
1.343 avankest 741: <li><p>Drop
1.346 avankest 742: <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 743: <var title="">url</var>.</li>
744:
745: <li><p>If the <code>"user:password"</code> format in the
746: <code class="external"><a href="http://tools.ietf.org/html/rfc2616/#section-3.2.1">userinfo</a></code> production is not supported
747: for the relevant
1.346 avankest 748: <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 749: <var title="">url</var> contains this format,
750: <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 751: "<code class="external"><a href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#syntaxerror">SyntaxError</a></code>" and terminate these
752: steps.
1.89 avankest 753:
1.314 avankest 754: <!-- XXX need to throw here for "user:password" or just "user" for
755: cross-origin unless we solve this in another way -->
1.2 avankest 756:
1.343 avankest 757: <li><p>If <var title="">url</var> contains the <code>"user:password"</code>
758: format let <var>temp user</var> be the user part and
759: <var>temp password</var> be the password part.</li>
1.2 avankest 760:
1.343 avankest 761: <li><p>If <var title="">url</var> just contains the <code>"user"</code>
762: format let <var>temp user</var> be the user part.</li>
1.2 avankest 763:
1.364 avankest 764: <li>
765: <p>Let <var>async</var> be the value of the <var>async</var> argument or
766: true if it was omitted.
767:
768:
1.2 avankest 769:
1.205 avankest 770: <li>
1.343 avankest 771: <p>If the <var title="">user</var> argument was not omitted follow these
772: sub steps:</p>
1.2 avankest 773:
1.60 avankest 774: <ol>
1.343 avankest 775: <li><p>If <var title="">user</var> is not null and the
1.346 avankest 776: <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
777: <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 778: <a href="#xmlhttprequest-origin"><code>XMLHttpRequest</code> origin</a>,
779: <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 780: "<code class="external"><a href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#invalidaccesserror">InvalidAccessError</a></code>" exception and
781: terminate the overall set of steps.
1.2 avankest 782:
1.343 avankest 783: <li><p>Let <var>temp user</var> be <var>user</var>.</li>
1.205 avankest 784: </ol>
1.184 avankest 785:
1.343 avankest 786: <p class="note">These steps override anything that may have been set by
787: the <var title="">url</var> argument.</p>
788: </li>
1.157 avankest 789:
1.205 avankest 790: <li>
1.343 avankest 791: <p>If the <var title="">password</var> argument was not omitted follow
792: these sub steps:</p>
1.2 avankest 793:
1.205 avankest 794: <ol>
1.343 avankest 795: <li><p>If <var title="">password</var> is not null and the
1.346 avankest 796: <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
797: <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 798: <a href="#xmlhttprequest-origin"><code>XMLHttpRequest</code> origin</a>,
799: <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 800: "<code class="external"><a href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#invalidaccesserror">InvalidAccessError</a></code>" exception and
801: terminate the overall set of steps.</li>
1.2 avankest 802:
1.343 avankest 803: <li><p>Let <var>temp password</var> be <var>password</var>.</li>
1.205 avankest 804: </ol>
1.102 avankest 805:
1.343 avankest 806: <p class="note">These steps override anything that may have been set by
807: the <var title="">url</var> argument.</p>
808: </li>
1.2 avankest 809:
1.343 avankest 810: <li><p><a href="#terminate-abort" title="terminate abort()">Terminate the <code>abort()</code> algorithm</a>.</li>
1.319 avankest 811:
1.343 avankest 812: <li><p><a href="#terminate-send" title="terminate send()">Terminate the <code>send()</code> algorithm</a>.</li>
1.2 avankest 813:
1.343 avankest 814: <li><p>The user agent should cancel any network
815: activity for which the object is responsible.</li>
1.205 avankest 816: <!-- we can hardly require it... -->
1.24 avankest 817:
1.343 avankest 818: <li><p>If there are any
1.346 avankest 819: <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 820: object's <a href="#xmlhttprequest-task-source"><code>XMLHttpRequest</code> task source</a> in one of
1.346 avankest 821: 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 822: then remove them.
1.254 avankest 823:
824: <li>
1.205 avankest 825: <p>Set variables associated with the object as follows:</p>
1.70 avankest 826:
1.205 avankest 827: <ul>
1.17 avankest 828:
1.343 avankest 829: <li><p>Set the <a href="#request-method">request method</a> to <var>method</var>.</li>
830:
831: <li><p>Set the <a href="#request-url">request URL</a> to <var title="">url</var>.</li>
832:
1.363 avankest 833: <li><p>If <var>async</var> is false, set the
834: <a href="#synchronous-flag">synchronous flag</a>.
1.341 avankest 835:
1.343 avankest 836: <li><p>Set the <a href="#request-username">request username</a> to <var>temp user</var>.</li>
1.341 avankest 837:
1.343 avankest 838: <li><p>Set the <a href="#request-password">request password</a> to <var>temp password</var>.</li>
1.17 avankest 839:
1.343 avankest 840: <li><p>Empty the list of <a href="#author-request-headers">author request headers</a>.</p>
1.308 avankest 841:
1.343 avankest 842: <li><p>Set the <a href="#send-flag"><code>send()</code> flag</a> to false.</li>
1.17 avankest 843:
1.343 avankest 844: <li><p>Set <a href="#response-entity-body">response entity body</a> to null.</li>
1.205 avankest 845: </ul>
1.343 avankest 846: </li>
1.44 avankest 847:
1.360 avankest 848: <li><p>Change the state to
1.343 avankest 849: <a href="#dom-xmlhttprequest-opened" title="dom-XMLHttpRequest-OPENED">OPENED</a>.</li>
1.176 avankest 850:
1.343 avankest 851: <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 852: </ol>
1.22 avankest 853:
1.275 avankest 854:
1.343 avankest 855:
1.350 avankest 856: <h4 id="the-setrequestheader-method"><span class="secno">4.7.2 </span>The <code title="">setRequestHeader()</code> method</h4>
1.343 avankest 857:
858: <dl class="domintro">
859: <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 860:
861: <dd>
1.343 avankest 862: <p>Appends an header to the list of
863: <a href="#author-request-headers">author request headers</a>, or if <var>header</var> is already
864: in the list of <a href="#author-request-headers">author request headers</a>, combines its value
865: with <var>value</var>.</p>
866:
1.357 avankest 867: <p>Throws an "<code class="external"><a href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#invalidstateerror">InvalidStateError</a></code>"
868: exception if the state is not
869: <a href="#dom-xmlhttprequest-opened" title="dom-XMLHttpRequest-OPENED">OPENED</a> or if the
1.343 avankest 870: <a href="#send-flag"><code>send()</code> flag</a> is true.</p>
871:
1.357 avankest 872: <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 873: <var title="">header</var> is not a valid HTTP header field name or if
874: <var title="">value</var> is not a valid HTTP header field value.</p>
875: </dd>
1.275 avankest 876: </dl>
1.205 avankest 877:
1.343 avankest 878: <p class="note">As indicated in the algorithm below certain headers cannot
879: be set and are left up to the user agent. In addition there are certain
880: other headers the user agent will take control of if they are not set by
881: the author as indicated at the end of the
882: <code title="dom-XMLHttpRequest-send"><a href="#dom-xmlhttprequest-send">send()</a></code> method section.</p>
883:
884:
885:
1.366 ! avankest 886: <p>The
1.343 avankest 887: <dfn id="dom-xmlhttprequest-setrequestheader" title="dom-XMLHttpRequest-setRequestHeader"><code>setRequestHeader(<var title="">header</var>, <var title="">value</var>)</code></dfn>
1.366 ! avankest 888: method must run these steps:</p>
1.6 avankest 889:
1.205 avankest 890: <ol>
1.356 avankest 891: <li><p>If the state is not
892: <a href="#dom-xmlhttprequest-opened" title="dom-XMLHttpRequest-OPENED">OPENED</a>,
893: <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 894: "<code class="external"><a href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#invalidstateerror">InvalidStateError</a></code>" exception and
895: terminate these steps.
1.356 avankest 896:
897: <li><p>If the <a href="#send-flag"><code>send()</code> flag</a> is true,
898: <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 899: "<code class="external"><a href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#invalidstateerror">InvalidStateError</a></code>" exception and
900: terminate these steps.
1.343 avankest 901:
902: <li><p>If any code point in <var>header</var> is higher than
903: U+00FF LATIN SMALL LETTER Y WITH DIAERESIS or after
904: <a href="#deflate-a-domstring-into-a-byte-sequence" title="deflate a DOMString into a byte sequence">deflating</a>
905: <var>header</var> it does not match the
1.356 avankest 906: <a class="external" href="http://tools.ietf.org/html/rfc2616/#section-4.2">field-name</a> production,
907: <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 908: "<code class="external"><a href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#syntaxerror">SyntaxError</a></code>" exception and terminate
909: these steps. Otherwise let <var>header</var> be the result of
1.343 avankest 910: <a href="#deflate-a-domstring-into-a-byte-sequence" title="deflate a DOMString into a byte sequence">deflating</a>
911: <var>header</var>.</li> <!-- This sounds lame, but it works. -->
912:
913: <li>
914: <p>If any code point in <var>value</var> is higher than
915: U+00FF LATIN SMALL LETTER Y WITH DIAERESIS or after
916: <a href="#deflate-a-domstring-into-a-byte-sequence" title="deflate a DOMString into a byte sequence">deflating</a>
917: <var>value</var> it does not match the
1.356 avankest 918: <a class="external" href="http://tools.ietf.org/html/rfc2616/#section-4.2">field-value</a> production,
919: <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 920: "<code class="external"><a href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#syntaxerror">SyntaxError</a></code>" exception and terminate
921: these steps. Otherwise let <var>value</var> be the result of
1.343 avankest 922: <a href="#deflate-a-domstring-into-a-byte-sequence" title="deflate a DOMString into a byte sequence">deflating</a>
923: <var>value</var>.</p> <!-- This sounds lame, but it works. -->
1.47 avankest 924:
1.343 avankest 925: <p class="note">The empty string is legal and represents the empty
926: header value.</p>
1.258 avankest 927: </li>
1.6 avankest 928:
1.205 avankest 929: <li>
1.343 avankest 930: <p>Terminate these steps if <var>header</var> is a case-insensitive
931: match for one of the following headers:</p>
1.179 avankest 932:
1.205 avankest 933: <ul>
1.343 avankest 934: <li><code>Accept-Charset</code></li>
935: <li><code>Accept-Encoding</code></li>
936: <li><code>Connection</code></li>
937: <li><code>Content-Length</code></li>
938: <li><code>Cookie</code></li>
939: <li><code>Cookie2</code></li>
940: <li><code>Content-Transfer-Encoding</code></li>
941: <li><code>Date</code></li>
942: <li><code>Expect</code></li>
943: <li><code>Host</code></li>
944: <li><code>Keep-Alive</code></li>
945: <li><code>Referer</code></li>
946: <li><code>TE</code></li>
947: <li><code>Trailer</code></li>
948: <li><code>Transfer-Encoding</code></li>
949: <li><code>Upgrade</code></li>
950: <li><code>User-Agent</code></li>
951: <li><code>Via</code></li>
1.205 avankest 952: </ul>
1.69 avankest 953:
1.258 avankest 954: <p>… or if the start of <var>header</var> is a case-insensitive
1.343 avankest 955: match for <code>Proxy-</code> or <code>Sec-</code> (including when
956: <var>header</var> is just <code>Proxy-</code> or <code>Sec-</code>).</p>
1.342 avankest 957:
1.343 avankest 958: <p class="note">The above headers are controlled by the user agent to
959: let it control those aspects of transport. This guarantees data
960: integrity to some extent. Header names starting with <code>Sec-</code>
961: are not allowed to be set to allow new headers to be minted that are
962: guaranteed not to come from <code><a href="#xmlhttprequest">XMLHttpRequest</a></code>.</p>
963: </li>
1.205 avankest 964:
1.343 avankest 965: <li><p>If <var>header</var> is not in the
966: <a href="#author-request-headers">author request headers</a> list append <var>header</var> with
967: its associated <var>value</var> to the list and terminate these
968: steps.</li>
969:
970: <li><p>If <var>header</var> is in the <a href="#author-request-headers">author request headers</a>
971: list either use multiple headers, combine the values or use a combination
972: of those (section 4.2, RFC 2616).
973: <a href="#refsHTTP">[HTTP]</a>
974: <!-- XXX it seems UAs always combine the values -->
1.205 avankest 975: </ol>
1.18 avankest 976:
1.343 avankest 977: <p class="note">See also the
978: <code title="dom-XMLHttpRequest-send"><a href="#dom-xmlhttprequest-send">send()</a></code> method regarding user
979: agent header handling for caching, authentication, proxies, and
980: cookies.</p>
1.47 avankest 981:
1.343 avankest 982: <div class="example">
1.316 avankest 983: <p>Some simple code demonstrating what happens when setting the same
1.343 avankest 984: header twice:</p>
1.316 avankest 985:
1.205 avankest 986: <pre><code>// The following script:
1.18 avankest 987: var client = new XMLHttpRequest();
988: client.open('GET', 'demo.cgi');
989: client.setRequestHeader('X-Test', 'one');
990: client.setRequestHeader('X-Test', 'two');
991: client.send();
992:
1.316 avankest 993: // …results in the following header being sent:
994: X-Test: one, two</code></pre>
1.205 avankest 995: </div>
1.6 avankest 996:
1.343 avankest 997:
1.341 avankest 998:
1.276 avankest 999:
1.350 avankest 1000: <h4 id="the-send-method"><span class="secno">4.7.3 </span>The <code title="">send()</code> method</h4>
1.343 avankest 1001:
1002: <dl class="domintro">
1003: <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 1004: <dd>
1.343 avankest 1005: <p>Initiates the request. The optional argument provides the
1006: <a href="#request-entity-body">request entity body</a>. The argument is ignored if
1007: <a href="#request-method">request method</a> is <code>GET</code> or
1008: <code>HEAD</code>.</p>
1009:
1.357 avankest 1010: <p>Throws an "<code class="external"><a href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#invalidstateerror">InvalidStateError</a></code>"
1011: exception if the state is not
1012: <a href="#dom-xmlhttprequest-opened" title="dom-XMLHttpRequest-OPENED">OPENED</a> or if the
1013: <a href="#send-flag"><code>send()</code> flag</a> is true.</p>
1.343 avankest 1014: </dd>
1.276 avankest 1015: </dl>
1.205 avankest 1016:
1.366 ! avankest 1017: <p>The
1.343 avankest 1018: <dfn id="dom-xmlhttprequest-send" title="dom-XMLHttpRequest-send"><code>send(<var>data</var>)</code></dfn>
1.366 ! avankest 1019: method must run these steps (unless otherwise noted). This algorithm can
! 1020: be <dfn id="terminate-send" title="terminate send()">terminated</dfn> by invoking the
1.343 avankest 1021: <code title="dom-XMLHttpRequest-open"><a href="#dom-xmlhttprequest-open">open()</a></code> or
1022: <code title="dom-XMLHttpRequest-abort"><a href="#dom-xmlhttprequest-abort">abort()</a></code> method. When it is
1023: <a href="#terminate-send" title="terminate send()">terminated</a> the user agent
1.366 ! avankest 1024: must terminate the algorithm after finishing the step it is on.</p>
1.343 avankest 1025:
1026: <p class="note">The <code title="dom-XMLHttpRequest-send"><a href="#dom-xmlhttprequest-send">send()</a></code>
1.366 ! avankest 1027: algorithm can only be terminated if the <a href="#synchronous-flag">synchronous flag</a> is
! 1028: unset and only after the method call has returned.</p>
1.60 avankest 1029:
1.205 avankest 1030: <ol>
1.356 avankest 1031: <li><p>If the state is not
1032: <a href="#dom-xmlhttprequest-opened" title="dom-XMLHttpRequest-OPENED">OPENED</a>,
1033: <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 1034: "<code class="external"><a href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#invalidstateerror">InvalidStateError</a></code>" exception and
1035: terminate these steps.
1.356 avankest 1036:
1037: <li><p>If the <a href="#send-flag"><code>send()</code> flag</a> is true,
1038: <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 1039: "<code class="external"><a href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#invalidstateerror">InvalidStateError</a></code>" exception and
1040: terminate these steps.
1.343 avankest 1041:
1042: <li>
1043: <p>If the <a href="#request-method">request method</a> is a case-sensitive match for
1044: <code>GET</code> or <code>HEAD</code> act as if <var title="">data</var>
1045: is null.</p>
1046:
1047: <p>If the <var>data</var> argument has been omitted or is
1048: null, do not include a <a href="#request-entity-body">request entity body</a>
1049: and go to the next step.</p>
1.342 avankest 1050:
1.343 avankest 1051: <p>Otherwise, let <var>encoding</var> be null, <var>mime type</var> be
1052: null, and then follow these rules:</p>
1.342 avankest 1053:
1.343 avankest 1054: <dl class="switch">
1055:
1.60 avankest 1056:
1.343 avankest 1057: <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 1058:
1059: <dd>
1.343 avankest 1060: <p>Let <var>encoding</var> be the
1061: <a class="external" href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#preferred-mime-name">preferred MIME name</a> of the
1062: <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>
1063: of <var>data</var>. If <var>encoding</var> is UTF-16 change it to
1064: UTF-8.</p>
1.234 avankest 1065:
1.307 avankest 1066: <p>Let <var>mime type</var> be "<code>application/xml</code>" or
1.343 avankest 1067: "<code>text/html</code>" if
1.349 avankest 1068: <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 1069: <a class="external" href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#html-document">HTML document</a>, followed by
1070: "<code>;charset=</code>", followed by <var>encoding</var>.</p>
1071:
1072: <p>Let the <a href="#request-entity-body">request entity body</a> be the result of getting
1.356 avankest 1073: the <code>innerHTML</code>
1.343 avankest 1074: attribute on <var>data</var>
1075: <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 1076: and encoded as <var>encoding</var>. Re-throw any exception this
1077: throws.</p> <!-- XXX replace innerHTML somehow -->
1.343 avankest 1078:
1079: <p class="note">In particular, if the document cannot be serialized an
1.357 avankest 1080: "<code class="external"><a href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#invalidstateerror">InvalidStateError</a></code>" exception is
1081: thrown.</p>
1.343 avankest 1082:
1083: <p class="note">Subsequent changes to the
1084: <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
1085: is transferred.</p>
1086: </dd>
1.239 avankest 1087:
1.343 avankest 1088: <dt>If <var>data</var> is a <code>DOMString</code></dt>
1.239 avankest 1089:
1090: <dd>
1.250 avankest 1091: <p>Let <var>encoding</var> be UTF-8.</p>
1092:
1093: <p>Let <var>mime type</var> be "<code>text/plain;charset=UTF-8</code>".</p>
1094:
1.343 avankest 1095: <p>Let the <a href="#request-entity-body">request entity body</a> be <var>data</var>
1096: <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>
1097: and encoded as UTF-8.</p>
1098: </dd>
1099:
1100:
1.205 avankest 1101: </dl>
1.103 avankest 1102:
1.343 avankest 1103: <p>If a <code>Content-Type</code> header is set using
1104: <code title="dom-XMLHttpRequest-setRequestHeader"><a href="#dom-xmlhttprequest-setrequestheader">setRequestHeader()</a></code>
1.346 avankest 1105: 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 1106: has a <code>charset</code> parameter whose value is not a case-insensitive
1107: match for <var title="">encoding</var>, and <var title="">encoding</var>
1108: is not null, set all the <code>charset</code> parameters of the
1109: <code>Content-Type</code> header to <var title="">encoding</var>.</p>
1110:
1111: <p>If no <code>Content-Type</code> header has been set using
1112: <code title="dom-XMLHttpRequest-setRequestHeader"><a href="#dom-xmlhttprequest-setrequestheader">setRequestHeader()</a></code>
1113: and <var title="">mime type</var> is not null set a
1114: <code>Content-Type</code> request header with as value
1115: <var title="">mime type</var>.</p>
1116:
1.238 avankest 1117: <!-- reminder: if we ever change this to always include charset it has
1118: to be included as the first parameter for compatibility reasons -->
1.343 avankest 1119: </li>
1120:
1.363 avankest 1121: <li><p>If the <a href="#synchronous-flag">synchronous flag</a> is set release the
1.346 avankest 1122: <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 1123:
1124:
1.341 avankest 1125:
1.343 avankest 1126: <li><p>Set the <a href="#error-flag">error flag</a> to false.</li>
1.341 avankest 1127:
1.343 avankest 1128:
1.164 avankest 1129:
1.205 avankest 1130: <li>
1.363 avankest 1131: <p>If the <a href="#synchronous-flag">synchronous flag</a> is unset, run these substeps:</p>
1.213 avankest 1132:
1133: <ol>
1.343 avankest 1134: <li><p>Set the <a href="#send-flag"><code>send()</code> flag</a> to true.</li>
1135:
1.342 avankest 1136: <li>
1.343 avankest 1137: <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 1138:
1.343 avankest 1139: <p class="note">The state does not change. The event is dispatched for
1140: historical reasons.</p>
1141: </li>
1.219 avankest 1142:
1.343 avankest 1143:
1.213 avankest 1144:
1.343 avankest 1145: <li><p>Return the <code title="dom-XMLHttpRequest-send"><a href="#dom-xmlhttprequest-send">send()</a></code>
1146: method call, but continue running the steps in this algorithm.</li>
1.213 avankest 1147: </ol>
1.343 avankest 1148: </li>
1.213 avankest 1149:
1150: <li>
1.343 avankest 1151: <dl class="switch">
1152: <dt>If the <a href="#xmlhttprequest-origin"><code>XMLHttpRequest</code> origin</a> and the
1.346 avankest 1153: <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 1154:
1.205 avankest 1155: <dd>
1.343 avankest 1156: <p>These are the <dfn id="same-origin-request-steps">same-origin request steps</dfn>.</p>
1.342 avankest 1157:
1.346 avankest 1158: <p><a class="external" href="http://www.whatwg.org/specs/web-apps/current-work/multipage/urls.html#fetch">Fetch</a> the
1.343 avankest 1159: <a href="#request-url">request URL</a> from <i title="">origin</i>
1160: <a href="#xmlhttprequest-origin"><code>XMLHttpRequest</code> origin</a>, with the
1161: <i title="">synchronous flag</i> set if the
1.363 avankest 1162: <a href="#synchronous-flag">synchronous flag</a> is set, using HTTP method
1.343 avankest 1163: <a href="#request-method">request method</a>, user <a href="#request-username">request username</a> (if
1164: non-null) and password <a href="#request-password">request password</a> (if non-null),
1165: taking into account the <a href="#request-entity-body">request entity body</a>, list of
1166: <a href="#author-request-headers">author request headers</a> and the rules listed at the end of
1167: this section.</p>
1.305 avankest 1168:
1.343 avankest 1169: <dl class="switch">
1.363 avankest 1170: <dt>If the <a href="#synchronous-flag">synchronous flag</a> is set</dt>
1.343 avankest 1171: <dd>
1172: <p>While making the request also follow the
1173: <a href="#same-origin-request-event-rules">same-origin request event rules</a>.</p>
1.305 avankest 1174:
1175: <!--
1.250 avankest 1176: This cannot involve any task queue whatsoever because that would
1177: mean other tasks on the task queue might get processed as well
1178: which is counter to the whole idea of doing things synchronous.
1179: -->
1.305 avankest 1180:
1.343 avankest 1181: <p class="note">The
1182: <code title="dom-XMLHttpRequest-send"><a href="#dom-xmlhttprequest-send">send()</a></code> method call will
1183: now be returned by virtue of this algorithm ending.</p>
1184: </dd>
1.305 avankest 1185:
1.363 avankest 1186: <dt>If the <a href="#synchronous-flag">synchronous flag</a> is unset</dt>
1.305 avankest 1187: <dd>
1.343 avankest 1188:
1189:
1.305 avankest 1190: <p>While processing the request, as data becomes available and when
1.343 avankest 1191: the user interferes with the request,
1.346 avankest 1192: <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 1193: to update the <a href="#response-entity-body">response entity body</a> and follow the
1194: <a href="#same-origin-request-event-rules">same-origin request event rules</a>.</p>
1195: </dd>
1.305 avankest 1196: </dl>
1.343 avankest 1197: </dd>
1.205 avankest 1198:
1.343 avankest 1199: <dt>Otherwise</dt>
1.205 avankest 1200: <dd>
1.343 avankest 1201: <p>These are the <dfn id="cross-origin-request-steps">cross-origin request steps</dfn>.</p>
1.250 avankest 1202:
1.343 avankest 1203:
1.305 avankest 1204: <p>This is a <a href="#network-error">network error</a>.</p>
1.343 avankest 1205:
1206:
1207:
1208: </dd>
1.205 avankest 1209: </dl>
1.343 avankest 1210: </li>
1.205 avankest 1211: </ol>
1.124 avankest 1212:
1.205 avankest 1213: <hr>
1214:
1.343 avankest 1215: <p>If the user agent allows the end user to configure a proxy it
1216: should modify the request appropriately; i.e., connect
1217: to the proxy host instead of the origin server, modify the
1218: <code>Request-Line</code> and send <code>Proxy-Authorization</code>
1219: headers as specified.</p>
1.214 avankest 1220:
1.264 avankest 1221: <hr>
1222:
1.343 avankest 1223: <p>If the user agent supports HTTP Authentication and
1224: <code title="http-authorization">Authorization</code> is not in the list
1225: of <a href="#author-request-headers">author request headers</a>, it should
1226: consider requests originating from the <code><a href="#xmlhttprequest">XMLHttpRequest</a></code> object
1227: to be part of the protection space that includes the accessed URIs and
1228: send <code title="http-authorization">Authorization</code> headers and
1229: handle <code>401 Unauthorized</code> requests appropriately.</p>
1230:
1231: <p>If authentication fails,
1232: <a href="#xmlhttprequest-origin"><code>XMLHttpRequest</code> origin</a> and the
1.346 avankest 1233: <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 1234: <code title="http-authorization">Authorization</code> is not in the list
1235: of <a href="#author-request-headers">author request headers</a>, <a href="#request-username">request username</a> is
1236: null, and <a href="#request-password">request password</a> is null, user agents
1237: should prompt the end user for their username and
1238: password.</p>
1239:
1240: <p>Otherwise, if authentication fails, user agents
1241: must not prompt the end user for their username and
1242: password. <a href="#refsHTTPAUTH">[HTTPAUTH]</a>
1.315 avankest 1243:
1.343 avankest 1244: <p class="note">End users are not prompted for various cases so that
1245: authors can implement their own user interface.</p>
1.214 avankest 1246:
1.264 avankest 1247: <hr>
1248:
1.343 avankest 1249: <p>If the user agent supports HTTP State Management it
1250: should persist, discard and send cookies (as received
1251: in the <code>Set-Cookie</code> response header, and sent in the
1252: <code>Cookie</code> header) as applicable.
1253: <a href="#refsCOOKIES">[COOKIES]</a>
1.214 avankest 1254:
1.264 avankest 1255: <hr>
1256:
1.343 avankest 1257: <p>If the user agent implements a HTTP cache it should
1258: respect <code>Cache-Control</code> request headers set by the
1259: <code title="dom-XMLHttpRequest-setRequestHeader"><a href="#dom-xmlhttprequest-setrequestheader">setRequestHeader()</a></code>
1260: (e.g., <code>Cache-Control: no-cache</code> bypasses the cache). It
1261: must not send <code>Cache-Control</code> or
1262: <code>Pragma</code> request headers automatically unless the end user
1263: explicitly requests such behavior (e.g. by reloading the page).</p>
1264:
1265: <p>For <code>304 Not Modified</code> responses that are a result of a
1266: user agent generated conditional request the user agent
1267: must act as if the server gave a <code>200 OK</code>
1268: response with the appropriate content. The user agent
1269: must allow
1270: <code title="dom-XMLHttpRequest-setRequestHeader"><a href="#dom-xmlhttprequest-setrequestheader">setRequestHeader()</a></code>
1271: to override automatic cache validation by setting request headers (e.g.
1272: <code>If-None-Match</code> or <code>If-Modified-Since</code>), in which
1273: case <code>304 Not Modified</code> responses must be
1274: passed through. <a href="#refsHTTP">[HTTP]</a>
1.214 avankest 1275:
1.264 avankest 1276: <hr>
1277:
1.343 avankest 1278: <p>If the user agent implements server-driven content-negotiation
1279: it must follow these constraints for the
1280: <code>Accept</code> and <code>Accept-Language</code> request headers:</p>
1.233 avankest 1281:
1282: <ul>
1.343 avankest 1283: <li><p>Both headers must not be modified if they are
1284: already set through
1285: <code title="dom-XMLHttpRequest-setRequestHeader"><a href="#dom-xmlhttprequest-setrequestheader">setRequestHeader()</a></code>.</li>
1286:
1287: <li><p>If not set through
1288: <code title="dom-XMLHttpRequest-setRequestHeader"><a href="#dom-xmlhttprequest-setrequestheader">setRequestHeader()</a></code>
1289: <code>Accept-Language</code> should be set as
1290: appropriate.</li>
1291:
1292: <li><p>If not set through
1293: <code title="dom-XMLHttpRequest-setRequestHeader"><a href="#dom-xmlhttprequest-setrequestheader">setRequestHeader()</a></code>
1294: <code>Accept</code> must be set with as value
1295: <code>*/*</code>.</li>
1.233 avankest 1296: </ul>
1297:
1.343 avankest 1298: <p>Responses must have the content-encodings
1299: automatically decoded. <a href="#refsHTTP">[HTTP]</a>
1.214 avankest 1300:
1.264 avankest 1301: <hr>
1302:
1.343 avankest 1303: <p>Besides the <a href="#author-request-headers">author request headers</a> user agents
1304: should not include additional request headers other than those mentioned
1305: above or other than those authors are not allowed to set using
1306: <code title="dom-XMLHttpRequest-setRequestHeader"><a href="#dom-xmlhttprequest-setrequestheader">setRequestHeader()</a></code>.
1307: This ensures that authors have a reasonably predictable API.</p>
1.214 avankest 1308:
1309:
1.350 avankest 1310: <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 1311:
1.343 avankest 1312: <p>The <dfn id="same-origin-request-event-rules">same-origin request event rules</dfn> are as follows:</p>
1.205 avankest 1313:
1.343 avankest 1314: <dl class="switch">
1315: <dt>If the response has an HTTP status code of 301, 302, 303, or 307</dt>
1.205 avankest 1316: <dd>
1.343 avankest 1317: <p>If the redirect violates infinite loop precautions this is a
1318: <a href="#network-error">network error</a>.</p>
1.205 avankest 1319:
1.305 avankest 1320: <p>Otherwise, run these steps:</p>
1321:
1322: <ol>
1.343 avankest 1323: <li><p>Set the <a href="#request-url">request URL</a> to the
1.346 avankest 1324: <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 1325: <code>Location</code> header.</li>
1326:
1327: <li><p>If the <a href="#xmlhttprequest-origin"><code>XMLHttpRequest</code> origin</a> and the
1.346 avankest 1328: <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>
1329: 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 1330: the redirect while observing the
1331: <a href="#same-origin-request-event-rules">same-origin request event rules</a>.
1.305 avankest 1332:
1.343 avankest 1333: <li><p>Otherwise, follow the <a href="#cross-origin-request-steps">cross-origin request steps</a>
1334: and terminate the steps for this algorithm.</li>
1.305 avankest 1335: </ol>
1.250 avankest 1336:
1.343 avankest 1337: <p class="note">HTTP places requirements on the user agent regarding the
1338: preservation of the <a href="#request-method">request method</a> and
1339: <a href="#request-entity-body">request entity body</a> during redirects, and also requires end
1340: users to be notified of certain kinds of automatic redirections.</p>
1.205 avankest 1341: <!-- XXX HTTP needs fixing here -->
1.343 avankest 1342: </dd>
1.205 avankest 1343:
1.343 avankest 1344: <dt>If the end user cancels the request</dt>
1345: <dd><p>This is an <a href="#abort-error">abort error</a>.</dd>
1.216 avankest 1346:
1.343 avankest 1347: <dt>If there is a network error</dt>
1.215 avankest 1348: <dd>
1349: <p>In case of DNS errors, TLS negotiation failure, or other type of
1.343 avankest 1350: network errors, this is a <a href="#network-error">network error</a>. Do not request any
1351: kind of end user interaction.</p>
1.342 avankest 1352:
1.343 avankest 1353: <p class="note">This does not include HTTP responses that indicate
1354: some type of error, such as HTTP status code 410.</p>
1355: </dd>
1356:
1357:
1358:
1359: <dt>Once all HTTP headers have been received, the
1.363 avankest 1360: <a href="#synchronous-flag">synchronous flag</a> is unset, and the HTTP status code of the
1.343 avankest 1361: response is not 301, 302, 303, or 307</dt>
1362: <dd><p><a href="#switch-headers-received">Switch to the HEADERS_RECEIVED state</a>.</dd>
1363:
1364: <dt>Once the first byte (or more) of the
1365: <a href="#response-entity-body">response entity body</a> has been received and the
1.363 avankest 1366: <a href="#synchronous-flag">synchronous flag</a> is unset</dt>
1.343 avankest 1367: <dt>If there is no <a href="#response-entity-body">response entity body</a> and the
1.363 avankest 1368: <a href="#synchronous-flag">synchronous flag</a> is unset</dt>
1.343 avankest 1369: <dd><p><a href="#switch-loading">Switch to the LOADING state</a>.</dd>
1370:
1371: <dt>Once the whole <a href="#response-entity-body">response entity body</a> has been
1372: received</dt>
1373: <dt>If there is no <a href="#response-entity-body">response entity body</a> and the state is
1374: <a href="#dom-xmlhttprequest-loading" title="dom-XMLHttpRequest-LOADING">LOADING</a></dt>
1375: <dt>If there is no <a href="#response-entity-body">response entity body</a> and the
1.363 avankest 1376: <a href="#synchronous-flag">synchronous flag</a> is set</dt>
1.343 avankest 1377: <dd><p><a href="#switch-done">Switch to the DONE state</a>.</dd>
1378: </dl>
1.342 avankest 1379:
1.343 avankest 1380:
1.60 avankest 1381:
1.342 avankest 1382: <hr>
1.6 avankest 1383:
1.343 avankest 1384: <p>When something is said to be a <dfn id="network-error">network error</dfn> run the
1385: <a href="#request-error">request error</a> steps for exception
1.357 avankest 1386: "<code class="external"><a href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#networkerror">NetworkError</a></code>".</p>
1.343 avankest 1387:
1388: <p>When something is said to be an <dfn id="abort-error">abort error</dfn> run the
1389: <a href="#request-error">request error</a> steps for exception
1.357 avankest 1390: "<code class="external"><a href="http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#aborterror">AbortError</a></code>".</p>
1.343 avankest 1391:
1392:
1393:
1394: <p>When something is said to be a <dfn id="request-error">request error</dfn> for
1395: exception <var>exception</var> run these
1396: steps:</p>
1.6 avankest 1397:
1.343 avankest 1398: <ol>
1399: <li><p>The user agent should cancel any network
1400: activity for which the object is responsible.</li>
1.84 avankest 1401:
1.343 avankest 1402: <li><p>If there are any
1.346 avankest 1403: <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 1404: object's <a href="#xmlhttprequest-task-source"><code>XMLHttpRequest</code> task source</a> in one of
1.346 avankest 1405: 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 1406: then remove them.
1.60 avankest 1407:
1.343 avankest 1408: <li><p>Set the the <a href="#error-flag">error flag</a> to true.</li>
1.256 avankest 1409:
1.360 avankest 1410: <li><p>Change the state to <a href="#dom-xmlhttprequest-done" title="dom-XMLHttpRequest-DONE">DONE</a>.</li>
1.252 avankest 1411:
1.363 avankest 1412: <li><p>If the <a href="#synchronous-flag">synchronous flag</a> is set,
1.356 avankest 1413: <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 1414: <var>exception</var> exception and terminate the overall set of
1415: steps.</li>
1.205 avankest 1416:
1.342 avankest 1417: <li>
1.343 avankest 1418: <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 1419:
1.343 avankest 1420: <p class="note">At this point it is clear that the
1.363 avankest 1421: <a href="#synchronous-flag">synchronous flag</a> is unset.</p>
1.343 avankest 1422: </li>
1.250 avankest 1423:
1.343 avankest 1424:
1.215 avankest 1425: </ol>
1.6 avankest 1426:
1.343 avankest 1427:
1428: <p class="note">A future version of this specification will dispatch an
1429: <code title="event-xhr-error">error</code>/<code title="event-xhr-abort">abort</code>
1430: event here as well. (Depending on the type of error.)
1431:
1.6 avankest 1432:
1.215 avankest 1433: <hr>
1.2 avankest 1434:
1.343 avankest 1435: <p>When it is said to
1436: <dfn id="switch-headers-received">switch to the HEADERS_RECEIVED state</dfn>
1437: run these steps:</p>
1.60 avankest 1438:
1.215 avankest 1439: <ol>
1.360 avankest 1440: <li><p>Change the state to <a href="#dom-xmlhttprequest-headers_received" title="dom-XMLHttpRequest-HEADERS_RECEIVED">HEADERS_RECEIVED</a>.</li>
1.125 avankest 1441:
1.343 avankest 1442: <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 1443: </ol>
1.205 avankest 1444:
1.343 avankest 1445: <p>When it is said to
1446: <dfn id="switch-loading">switch to the LOADING state</dfn> run these
1447: steps:</p>
1.205 avankest 1448:
1.215 avankest 1449: <ol>
1.360 avankest 1450: <li><p>Change the state to <a href="#dom-xmlhttprequest-loading" title="dom-XMLHttpRequest-LOADING">LOADING</a>.</li>
1.17 avankest 1451:
1.343 avankest 1452: <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 1453: </ol>
1.205 avankest 1454:
1.343 avankest 1455: <p>When it is said to
1456: <dfn id="switch-done">switch to the DONE state</dfn> run these steps:</p>
1.218 avankest 1457:
1458: <ol>
1.363 avankest 1459: <li><p>If the <a href="#synchronous-flag">synchronous flag</a> is set, update the
1.343 avankest 1460: <a href="#response-entity-body">response entity body</a>.</li>
1461:
1.360 avankest 1462: <li><p>Change the state to <a href="#dom-xmlhttprequest-done" title="dom-XMLHttpRequest-DONE">DONE</a>.</li>
1.341 avankest 1463:
1.343 avankest 1464: <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 1465:
1.343 avankest 1466:
1.218 avankest 1467: </ol>
1468:
1.343 avankest 1469:
1470:
1.280 avankest 1471:
1.350 avankest 1472: <h4 id="the-abort-method"><span class="secno">4.7.5 </span>The <code title="">abort()</code> method</h4>
1.341 avankest 1473:
1.343 avankest 1474: <dl class="domintro">
1475: <dt><var title="">client</var> . <code title="dom-XMLHttpRequest-abort"><a href="#dom-xmlhttprequest-abort">abort()</a></code></dt>
1476: <dd>Cancels any network activity.</dd>
1.280 avankest 1477: </dl>
1478:
1.366 ! avankest 1479: <p>The
1.343 avankest 1480: <dfn id="dom-xmlhttprequest-abort" title="dom-XMLHttpRequest-abort"><code>abort()</code></dfn>
1.366 ! avankest 1481: method must run these steps (unless otherwise noted). This algorithm can
! 1482: be <dfn id="terminate-abort" title="terminate abort()">terminated</dfn> by invoking the
1.343 avankest 1483: <code title="dom-XMLHttpRequest-open"><a href="#dom-xmlhttprequest-open">open()</a></code> method. When it is
1484: <a href="#terminate-abort" title="terminate abort()">terminated</a> the user agent
1.366 ! avankest 1485: must terminate the algorithm after finishing the step it is on.
1.343 avankest 1486:
1487: <p class="note">The <code title="dom-XMLHttpRequest-abort"><a href="#dom-xmlhttprequest-abort">abort()</a></code>
1488: algorithm can only be terminated by invoking
1489: <code title="dom-XMLHttpRequest-open"><a href="#dom-xmlhttprequest-open">open()</a></code> from an event
1490: handler.</p>
1.205 avankest 1491:
1492: <ol>
1.343 avankest 1493: <li><p><a href="#terminate-send" title="terminate send()">Terminate the <code>send()</code> algorithm</a>.</li>
1.202 avankest 1494:
1.343 avankest 1495: <li><p>The user agent should cancel any network
1496: activity for which the object is responsible.</li>
1.254 avankest 1497:
1.343 avankest 1498: <li><p>If there are any
1.346 avankest 1499: <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 1500: object's <a href="#xmlhttprequest-task-source"><code>XMLHttpRequest</code> task source</a> in one of
1.346 avankest 1501: 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 1502: then remove them.
1.205 avankest 1503:
1.343 avankest 1504: <li><p>Set the <a href="#error-flag">error flag</a> to true.</li>
1.205 avankest 1505:
1506: <li>
1.343 avankest 1507: <p>If the state is <a href="#dom-xmlhttprequest-unsent" title="dom-XMLHttpRequest-UNSENT">UNSENT</a>,
1508: <a href="#dom-xmlhttprequest-opened" title="dom-XMLHttpRequest-OPENED">OPENED</a> with the
1509: <a href="#send-flag"><code>send()</code> flag</a> being false, or
1510: <a href="#dom-xmlhttprequest-done" title="dom-XMLHttpRequest-DONE">DONE</a> go to the next step.</p>
1.205 avankest 1511:
1512: <p>Otherwise run these substeps:</p>
1513:
1514: <ol>
1.360 avankest 1515: <li><p>Change the state to <a href="#dom-xmlhttprequest-done" title="dom-XMLHttpRequest-DONE">DONE</a>.</li>
1.343 avankest 1516:
1517: <li><p>Set the <a href="#send-flag"><code>send()</code> flag</a> to false.</li>
1.341 avankest 1518:
1.343 avankest 1519: <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 1520:
1.343 avankest 1521:
1.60 avankest 1522: </ol>
1.17 avankest 1523:
1.343 avankest 1524:
1525: <p class="note">A future version of this specification will dispatch an
1526: <code title="event-xhr-abort">abort</code> event here.</p>
1527:
1528: </li>
1.220 avankest 1529:
1.205 avankest 1530: <li>
1.360 avankest 1531: <p>Change the state to <a href="#dom-xmlhttprequest-unsent" title="dom-XMLHttpRequest-UNSENT">UNSENT</a>.</p>
1.205 avankest 1532:
1.343 avankest 1533: <p class="note">No <code title="event-xhr-readystatechange">readystatechange</code> event is dispatched.</p>
1534: </li>
1.205 avankest 1535: </ol>
1536:
1537:
1538:
1.350 avankest 1539: <h3 id="response"><span class="secno">4.8 </span>Response</h3>
1.343 avankest 1540:
1.350 avankest 1541: <h4 id="the-status-attribute"><span class="secno">4.8.1 </span>The <code title="">status</code> attribute</h4>
1.341 avankest 1542:
1.343 avankest 1543: <dl class="domintro">
1544: <dt><var title="">client</var> . <code title="dom-XMLHttpRequest-status"><a href="#dom-xmlhttprequest-status">status</a></code></dt>
1545: <dd><p>Returns the HTTP status code.</dd>
1.281 avankest 1546: </dl>
1547:
1.343 avankest 1548: <p>The
1549: <dfn id="dom-xmlhttprequest-status" title="dom-XMLHttpRequest-status"><code>status</code></dfn>
1550: attribute must return the result of running these
1551: steps:</p>
1.224 avankest 1552:
1553: <ol>
1.343 avankest 1554: <li><p>If the state is <a href="#dom-xmlhttprequest-unsent" title="dom-XMLHttpRequest-UNSENT">UNSENT</a> or
1555: <a href="#dom-xmlhttprequest-opened" title="dom-XMLHttpRequest-OPENED">OPENED</a> return 0 and terminate these
1556: steps.</li>
1.224 avankest 1557:
1.343 avankest 1558: <li><p>If the <a href="#error-flag">error flag</a> is true return 0 and terminate
1559: these steps.</li>
1.224 avankest 1560:
1.343 avankest 1561: <li><p>Return the HTTP status code.</li>
1.224 avankest 1562: </ol>
1.205 avankest 1563:
1564:
1.350 avankest 1565: <h4 id="the-statustext-attribute"><span class="secno">4.8.2 </span>The <code title="">statusText</code> attribute</h4>
1.281 avankest 1566:
1.343 avankest 1567: <dl class="domintro">
1568: <dt><var title="">client</var> . <code title="dom-XMLHttpRequest-statusText"><a href="#dom-xmlhttprequest-statustext">statusText</a></code></dt>
1569: <dd><p>Returns the HTTP status text.</dd>
1.281 avankest 1570: </dl>
1571:
1.343 avankest 1572: <p>The
1573: <dfn id="dom-xmlhttprequest-statustext" title="dom-XMLHttpRequest-statusText"><code>statusText</code></dfn>
1574: attribute must return the result of running these
1575: steps:</p>
1.224 avankest 1576:
1577: <ol>
1.343 avankest 1578: <li><p>If the state is <a href="#dom-xmlhttprequest-unsent" title="dom-XMLHttpRequest-UNSENT">UNSENT</a> or
1579: <a href="#dom-xmlhttprequest-opened" title="dom-XMLHttpRequest-OPENED">OPENED</a> return the empty string and
1580: terminate these steps.</li>
1.224 avankest 1581:
1.343 avankest 1582: <li><p>If the <a href="#error-flag">error flag</a> is true return the empty string and
1583: terminate these steps.</li>
1.224 avankest 1584:
1.343 avankest 1585: <li><p>Return the HTTP status text.</li>
1.224 avankest 1586: </ol>
1.205 avankest 1587:
1588:
1.350 avankest 1589: <h4 id="the-getresponseheader-method"><span class="secno">4.8.3 </span>The <code title="">getResponseHeader()</code> method</h4>
1.283 avankest 1590:
1.343 avankest 1591: <dl class="domintro">
1592: <dt><var title="">client</var> . <code title="dom-XMLHttpRequest-getResponseHeader"><a href="#dom-xmlhttprequest-getresponseheader">getResponseHeader(<var title="">header</var>)</a></code></dt>
1593: <dd><p>Returns the header field value from the response of which the
1594: field name matches <var title="">header</var>, unless the field name is
1595: <code>Set-Cookie</code> or <code>Set-Cookie2</code>.</p>
1.283 avankest 1596: </dl>
1597:
1.366 ! avankest 1598: <p>The
1.343 avankest 1599: <dfn id="dom-xmlhttprequest-getresponseheader" title="dom-XMLHttpRequest-getResponseHeader"><code>getResponseHeader(<var title="">header</var>)</code></dfn>
1.366 ! avankest 1600: method must run these steps:
1.205 avankest 1601:
1602: <ol>
1.343 avankest 1603: <li><p>If the state is <a href="#dom-xmlhttprequest-unsent" title="dom-XMLHttpRequest-UNSENT">UNSENT</a> or
1604: <a href="#dom-xmlhttprequest-opened" title="dom-XMLHttpRequest-OPENED">OPENED</a> return null and terminate these
1605: steps.</li>
1606:
1607: <li><p>If the <a href="#error-flag">error flag</a> is true return null
1608: and terminate these steps.</li>
1609:
1610: <li><p>If any code point in <var>header</var> is higher than
1611: U+00FF LATIN SMALL LETTER Y WITH DIAERESIS return null and terminate
1612: these steps.</li>
1613:
1614: <li><p>Let <var>header</var> be the result of
1615: <a href="#deflate-a-domstring-into-a-byte-sequence" title="deflate a DOMString into a byte sequence">deflating</a>
1616: <var>header</var>.</li> <!-- This sounds lame, but it works. -->
1617:
1618: <li><p>If <var>header</var> is a case-insensitive match for
1619: <code>Set-Cookie</code> or <code>Set-Cookie2</code> return null and
1620: terminate these steps.</li>
1621:
1622: <li><p>If <var>header</var> is a case-insensitive match for multiple HTTP
1623: response headers, return the
1624: <a href="#inflate-a-byte-sequence-into-a-domstring" title="inflate a byte sequence into a DOMString">inflated</a>
1625: values of these headers as a single concatenated string separated from
1626: each other by a U+002C COMMA U+0020 SPACE character pair and terminate
1627: these steps.</li>
1628:
1629: <li><p>If <var>header</var> is a case-insensitive match for a single HTTP
1630: response header, return the
1631: <a href="#inflate-a-byte-sequence-into-a-domstring" title="inflate a byte sequence into a DOMString">inflated</a>
1632: value of that header and terminate these steps.</li>
1.342 avankest 1633:
1.343 avankest 1634: <li><p>Return null.</li>
1635: </ol>
1.342 avankest 1636:
1.343 avankest 1637:
1.342 avankest 1638:
1.343 avankest 1639: <div class="example">
1.342 avankest 1640:
1.252 avankest 1641: <p>For the following script:</p>
1642:
1643: <pre><code>var client = new XMLHttpRequest();
1644: client.open("GET", "unicorns-are-teh-awesome.txt", true);
1.6 avankest 1645: client.send();
1.16 avankest 1646: client.onreadystatechange = function() {
1.252 avankest 1647: if(this.readyState == 2) {
1648: print(client.getResponseHeader("Content-Type"));
1649: }
1650: }</code></pre>
1651:
1.343 avankest 1652: <p>The <code>print()</code> function will get to process something
1653: like:</p>
1.1 avankest 1654:
1.252 avankest 1655: <pre><code>text/plain; charset=UTF-8</code></pre>
1.205 avankest 1656: </div>
1657:
1.2 avankest 1658:
1.350 avankest 1659: <h4 id="the-getallresponseheaders-method"><span class="secno">4.8.4 </span>The <code title="">getAllResponseHeaders()</code> method</h4>
1.283 avankest 1660:
1.343 avankest 1661: <dl class="domintro">
1662: <dt><var title="">client</var> . <code title="dom-XMLHttpRequest-getAllResponseHeaders"><a href="#dom-xmlhttprequest-getallresponseheaders">getAllResponseHeaders()</a></code></dt>
1663: <dd><p>Returns all headers from the response, with the exception of those
1664: whose field name is <code>Set-Cookie</code> or
1665: <code>Set-Cookie2</code>.</dd>
1.283 avankest 1666: </dl>
1667:
1.366 ! avankest 1668: <p>The
1.343 avankest 1669: <dfn id="dom-xmlhttprequest-getallresponseheaders" title="dom-XMLHttpRequest-getAllResponseHeaders"><code>getAllResponseHeaders()</code></dfn>
1.366 ! avankest 1670: method must run these steps:</p>
1.6 avankest 1671:
1.205 avankest 1672: <ol>
1.343 avankest 1673: <li><p>If the state is <a href="#dom-xmlhttprequest-unsent" title="dom-XMLHttpRequest-UNSENT">UNSENT</a> or
1674: <a href="#dom-xmlhttprequest-opened" title="dom-XMLHttpRequest-OPENED">OPENED</a> return the empty string and
1675: terminate these steps.</li>
1676:
1677: <li><p>If the <a href="#error-flag">error flag</a> is true return the empty string and
1678: terminate these steps.</li>
1679:
1680: <li><p>Return all the HTTP headers, excluding headers that are a
1681: case-insensitive match for <code>Set-Cookie</code> or
1682: <code>Set-Cookie2</code>,
1683: <a href="#inflate-a-byte-sequence-into-a-domstring" title="inflate a byte sequence into a DOMString">inflated</a>,
1684: as a single string, with each header line
1685: separated by a U+000D CR U+000A LF pair, excluding the status line, and
1686: with each header name and header value separated by a
1687: U+003A COLON U+0020 SPACE pair.</li>
1688: </ol>
1.342 avankest 1689:
1.343 avankest 1690:
1.205 avankest 1691:
1.343 avankest 1692: <div class="example">
1.252 avankest 1693: <p>For the following script:</p>
1694:
1695: <pre><code>var client = new XMLHttpRequest();
1696: client.open("GET", "narwhals-too.txt", true);
1.205 avankest 1697: client.send();
1698: client.onreadystatechange = function() {
1.312 avankest 1699: if(this.readyState == 2) {
1700: print(this.getAllResponseHeaders());
1701: }
1.252 avankest 1702: }</code></pre>
1703:
1.343 avankest 1704: <p>The <code>print()</code> function will get to process something
1705: like:</p>
1.205 avankest 1706:
1.252 avankest 1707: <pre><code>Date: Sun, 24 Oct 2004 04:58:38 GMT
1.205 avankest 1708: Server: Apache/1.3.31 (Unix)
1709: Keep-Alive: timeout=15, max=99
1710: Connection: Keep-Alive
1711: Transfer-Encoding: chunked
1712: Content-Type: text/plain; charset=utf-8</code></pre>
1713: </div>
1714:
1.250 avankest 1715:
1.343 avankest 1716:
1.350 avankest 1717: <h4 id="response-entity-body-0"><span class="secno">4.8.5 </span>Response entity body</h4>
1.343 avankest 1718:
1719: <p>The <dfn id="response-mime-type">response MIME type</dfn> is the MIME
1720: type the <code>Content-Type</code> header contains without any
1721: parameters or null if the header could not be parsed properly or was
1722: omitted. The <dfn id="override-mime-type">override MIME type</dfn> is
1723: always null. <dfn id="final-mime-type">Final MIME type</dfn> is the
1724: override MIME type unless that is null in which case it is the response
1725: MIME type.</p>
1726:
1727: <p>The <dfn id="response-charset">response charset</dfn> is the value of
1728: the <code>charset</code> parameter of the <code>Content-Type</code> header
1729: or null if there was no <code>charset</code> parameter or if
1730: the header could not be parsed properly or was omitted. The
1731: <dfn id="override-charset">override charset</dfn> is always null.
1732: <dfn id="final-charset">Final charset</dfn> is the override charset unless
1733: that is null in which case it is the response charset.</p>
1734:
1735:
1736: <p class="note"><a href="#override-mime-type">Override MIME type</a> and
1737: <a href="#override-charset">override charset</a> are introduced here solely to make editing
1738: several levels of XMLHttpRequest simultaneously somewhat easier. Apologies
1739: for any confusion they might cause.</p>
1740:
1.250 avankest 1741:
1742: <hr>
1.205 avankest 1743:
1.343 avankest 1744: <p>The <dfn id="response-entity-body">response entity body</dfn> is the
1745: fragment of the <a class="external" href="http://tools.ietf.org/html/rfc2616/#section-7.2">entity body</a> of the
1746: response received so far
1747: (<a href="#dom-xmlhttprequest-loading" title="dom-XMLHttpRequest-LOADING">LOADING</a>) or the complete
1748: entity body of the response
1749: (<a href="#dom-xmlhttprequest-done" title="dom-XMLHttpRequest-DONE">DONE</a>). If the response
1750: does not have an entity body the response entity body is null.</p>
1751:
1752: <p class="note">The <a href="#response-entity-body">response entity body</a> is updated as part
1753: of the <code title="dom-XMLHttpRequest-send"><a href="#dom-xmlhttprequest-send">send()</a></code> algorithm.</p>
1.205 avankest 1754:
1755: <hr>
1756:
1.343 avankest 1757: <p>The <dfn id="text-response-entity-body">text response entity body</dfn>
1758: is a <code>DOMString</code> representing the <a href="#response-entity-body">response entity
1759: body</a>. The text response entity body is the return value of the
1760: following algorithm:</p>
1.205 avankest 1761:
1762: <ol>
1.343 avankest 1763: <li><p>If the response entity body is null return the empty string and
1764: terminate these steps.</p>
1.250 avankest 1765:
1.343 avankest 1766: <li><p>Let <var>charset</var> be the <a href="#final-charset">final charset</a>.</li>
1.205 avankest 1767:
1.343 avankest 1768: <li><p>Let <var>mime</var> be the <a href="#final-mime-type">final MIME type</a>.</li>
1.205 avankest 1769:
1.343 avankest 1770: <li><p>If <var>charset</var> is null and <var>mime</var> is null,
1771: <code>text/xml</code>, <code>application/xml</code> or ends in
1772: <code title="">+xml</code> use the rules set forth in the XML
1773: specifications to determine the character encoding. Let
1774: <var>charset</var> be the determined character encoding.</li>
1775:
1776: <li><p>If <var>charset</var> is null and <var>mime</var> is
1777: <code>text/html</code> follow the rules set forth in the HTML
1778: specification to determine the character encoding. Let
1779: <var>charset</var> be the determined character encoding.
1780: <a href="#refsHTML">[HTML]</a>
1.205 avankest 1781:
1782: <li>
1783: <p>If <var>charset</var> is null then, for each of the rows in the
1.343 avankest 1784: following table, starting with the first one and going down, if the first
1785: bytes of <var>bytes</var> match the bytes given in the first column, then
1786: let <var>charset</var> be the encoding given in the cell in the second
1787: column of that row. If there is no match <var>charset</var> remains
1788: null.</p>
1.205 avankest 1789:
1790: <table>
1791: <thead>
1792: <tr>
1793: <th>Bytes in Hexadecimal
1794: <th>Description
1.239 avankest 1795: <tbody>
1.205 avankest 1796: <tr>
1797: <td>FE FF
1798: <td>UTF-16BE BOM
1799: <tr>
1800: <td>FF FE
1801: <td>UTF-16LE BOM
1802: <tr>
1803: <td>EF BB BF
1.239 avankest 1804: <td>UTF-8 BOM
1.205 avankest 1805: </table>
1.343 avankest 1806: </li>
1.205 avankest 1807:
1.343 avankest 1808: <li><p>If <var>charset</var> is null let <var>charset</var> be
1809: UTF-8.</li>
1.205 avankest 1810:
1.343 avankest 1811: <li><p>Return the result of decoding the response entity body using
1812: <var>charset</var>. Replace bytes or sequences of bytes that are not
1813: valid accordng to the <var>charset</var> with a single
1814: U+FFFD REPLACEMENT CHARACTER character. Remove one leading
1815: U+FEFF BYTE ORDER MARK character, if present.</li>
1.205 avankest 1816: </ol>
1817:
1.343 avankest 1818: <p class="note">Authors are strongly encouraged to always encode their
1819: resources using UTF-8.</p>
1.205 avankest 1820:
1821: <hr>
1822:
1.343 avankest 1823: <p>The <dfn id="document-response-entity-body">document response entity
1824: 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
1825: <a href="#response-entity-body">response entity body</a> or null. If it is a
1.346 avankest 1826: <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 1827: <a href="#xmlhttprequest-origin"><code>XMLHttpRequest</code> origin</a>. If the
1828: <a href="#document-response-entity-body">document response entity body</a> has no value assigned to it let
1829: it be the return value of the following algorithm:</p>
1.89 avankest 1830:
1.205 avankest 1831: <ol>
1.343 avankest 1832: <li><p>If the <a href="#response-entity-body">response entity body</a> is null, return null and
1833: terminate these steps.</li>
1.342 avankest 1834:
1.343 avankest 1835: <li><p>If <a href="#final-mime-type">final MIME type</a> is not null,
1836: <code>text/xml</code>,
1837: <code>application/xml</code>, or does not end in
1838: <code title="">+xml</code>, return null and terminate these
1839: steps.</li>
1840:
1841:
1842:
1843: <li>
1844: <p>Let <var title="">document</var> be a
1845: <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
1846: <a href="#response-entity-body">response entity body</a> into a document tree following the
1847: rules set forth in the XML specifications. If that fails
1848: (unsupported character encoding, namespace well-formedness error et
1849: cetera) return null and terminate these steps.
1850: <a href="#refsXML">[XML]</a> <a href="#refsXMLNS">[XMLNS]</a>
1851:
1852: <p class="note">Scripts in the resulting document tree will not be executed,
1853: resources referenced will not be loaded and no associated XSLT will be
1854: applied.</p> <!-- XXX more formally?! -->
1855: </li>
1.6 avankest 1856:
1.343 avankest 1857: <li><p>Return <var title="">document</var>.</li>
1858: </ol>
1.12 avankest 1859:
1.343 avankest 1860:
1.76 avankest 1861:
1.12 avankest 1862:
1.350 avankest 1863: <h4 id="the-responsetext-attribute"><span class="secno">4.8.6 </span>The <code title="">responseText</code> attribute</h4>
1.281 avankest 1864:
1.343 avankest 1865: <dl class="domintro">
1866: <dt><var title="">client</var> . <code title="dom-XMLHttpRequest-responseText"><a href="#dom-xmlhttprequest-responsetext">responseText</a></code></dt>
1.281 avankest 1867: <dd>
1.343 avankest 1868: <p>Returns the <a href="#text-response-entity-body">text response entity body</a>.</p>
1869:
1870: </dd>
1.281 avankest 1871: </dl>
1872:
1.343 avankest 1873: <p>The
1874: <dfn id="dom-xmlhttprequest-responsetext" title="dom-XMLHttpRequest-responseText"><code>responseText</code></dfn>
1875: attribute must return the result of running these
1876: steps:</p>
1.6 avankest 1877:
1.205 avankest 1878: <ol>
1.343 avankest 1879:
1880:
1881: <li><p>If the state is not <a href="#dom-xmlhttprequest-loading" title="dom-XMLHttpRequest-LOADING">LOADING</a> or
1882: <a href="#dom-xmlhttprequest-done" title="dom-XMLHttpRequest-DONE">DONE</a> return the empty string and
1883: terminate these steps.</li>
1.341 avankest 1884:
1.343 avankest 1885: <li><p>If the <a href="#error-flag">error flag</a> is true return the empty string and
1886: terminate these steps.</li>
1.12 avankest 1887:
1.343 avankest 1888: <li><p>Return the <a href="#text-response-entity-body">text response entity body</a>.</li>
1.205 avankest 1889: </ol>
1.2 avankest 1890:
1891:
1.350 avankest 1892: <h4 id="the-responsexml-attribute"><span class="secno">4.8.7 </span>The <code title="">responseXML</code> attribute</h4>
1.281 avankest 1893:
1.343 avankest 1894: <dl class="domintro">
1895: <dt><var title="">client</var> . <code title="dom-XMLHttpRequest-responseXML"><a href="#dom-xmlhttprequest-responsexml">responseXML</a></code></dt>
1.281 avankest 1896: <dd>
1.343 avankest 1897: <p>Returns the <a href="#document-response-entity-body">document response entity body</a>.</p>
1898:
1899: </dd>
1.281 avankest 1900: </dl>
1901:
1.343 avankest 1902: <p>The
1903: <dfn id="dom-xmlhttprequest-responsexml" title="dom-XMLHttpRequest-responseXML"><code>responseXML</code></dfn>
1.344 avankest 1904: attribute must return the result of running these steps:</p>
1.2 avankest 1905:
1.205 avankest 1906: <ol>
1.343 avankest 1907:
1908:
1909: <li><p>If the state is not <a href="#dom-xmlhttprequest-done" title="dom-XMLHttpRequest-DONE">DONE</a> return
1910: null and terminate these steps.</li>
1.342 avankest 1911:
1.343 avankest 1912: <li><p>If the <a href="#error-flag">error flag</a> is true return null and terminate
1913: these steps.</li>
1.341 avankest 1914:
1.343 avankest 1915: <li><p>Return the <a href="#document-response-entity-body">document response entity body</a>.</li>
1.342 avankest 1916: </ol>
1.2 avankest 1917:
1.343 avankest 1918:
1.2 avankest 1919:
1.18 avankest 1920:
1.343 avankest 1921: <h2 class="no-num" id="references">References</h2>
1922: <h3 class="no-num" id="normative-references">Normative references</h3>
1923: <div id="anolis-references-normative"><dl><dt id="refsCOOKIES">[COOKIES]
1.346 avankest 1924: <dd><cite><a href="http://tools.ietf.org/html/rfc6265">HTTP State Management Mechanism</a></cite>, Adam Barth. IETF.
1.343 avankest 1925:
1.356 avankest 1926: <dt id="refsDOM">[DOM]
1927: <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 1928:
1929: <dt id="refsFILEAPI">[FILEAPI]
1.346 avankest 1930: <dd><cite><a href="http://dev.w3.org/2006/webapi/FileAPI/">File API</a></cite>, Arun Ranganathan and Jonas Sicking. W3C.
1.343 avankest 1931:
1932: <dt id="refsHTML">[HTML]
1.346 avankest 1933: <dd><cite><a href="http://www.whatwg.org/html">HTML</a></cite>, Ian Hickson. WHATWG.
1.343 avankest 1934:
1935: <dt id="refsHTTP">[HTTP]
1.347 avankest 1936: <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 1937:
1938: <dt id="refsHTTPAUTH">[HTTPAUTH]
1.347 avankest 1939: <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 1940:
1941: <dt id="refsHTTPVERBSEC">[HTTPVERBSEC]
1942: <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.
1943:
1944: <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.
1945:
1946: <dd><cite><a href="http://www.kb.cert.org/vuls/id/150227">HTTP proxy default configurations allow arbitrary TCP connections</a></cite>. US-CERT.
1947:
1948: <dt id="refsRFC2119">[RFC2119]
1.346 avankest 1949: <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 1950:
1951: <dt id="refsWEBIDL">[WEBIDL]
1.346 avankest 1952: <dd><cite><a href="http://dev.w3.org/2006/webapi/WebIDL/">Web IDL</a></cite>, Cameron McCormack. W3C.
1.343 avankest 1953:
1954: <dt id="refsXML">[XML]
1.346 avankest 1955: <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 1956:
1957: <dt id="refsXMLNS">[XMLNS]
1.346 avankest 1958: <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 1959:
1960: </dl></div>
1961:
1962: <h3 class="no-num" id="informative-references">Informative references</h3>
1963: <div id="anolis-references-informative"><dl><dt id="refsECMASCRIPT">[ECMASCRIPT]
1964: <dd><cite><a href="http://www.ecma-international.org/publications/standards/Ecma-262.htm">ECMAScript Language Specification</a></cite>. ECMA.
1965:
1966: </dl></div>
1967:
1968:
1969:
1970: <h2 class="no-num" id="acknowledgments">Acknowledgments</h2>
1971:
1972: <p>The editor would like to thank
1973:
1974: Addison Phillips,
1975: Ahmed Kamel,
1976: Alex Hopmann,
1977: Alex Vincent,
1978: Alexey Proskuryakov,
1979: Asbjørn Ulsberg,
1980: Boris Zbarsky,
1981: Björn Höhrmann,
1982: Cameron McCormack,
1983: Chris Marrin,
1984: Christophe Jolif,
1985: Charles McCathieNevile,
1986: Dan Winship,
1987: David Andersson,
1988: David Flanagan,
1989: David Håsäther,
1990: David Levin,
1991: Dean Jackson,
1992: Denis Sureau,
1993: Doug Schepers,
1994: Douglas Livingstone,
1995: Elliotte Harold,
1996: Eric Lawrence,
1997: Eric Uhrhane,
1998: Erik Dahlström,
1999: Geoffrey Sneddon,
2000: Gideon Cohn,
2001: Gorm Haug Eriksen,
2002: Håkon Wium Lie,
2003: Hallvord R. M. Steen,
2004: Henri Sivonen,
2005: Huub Schaeks,
2006: Ian Davis,
2007: Ian Hickson,
2008: Ivan Herman,
2009: Jeff Walden,
2010: Jens Lindström,
2011: Jim Deegan,
2012: Jim Ley,
2013: Joe Farro,
2014: Jonas Sicking,
2015: Julian Reschke,
2016: Karl Dubost,
2017: Lachlan Hunt,
2018: Maciej Stachowiak,
2019: Magnus Kristiansen,
2020: Marc Hadley,
2021: Marcos Caceres,
2022: Mark Baker,
2023: Mark Birbeck,
2024: Mark Nottingham,
2025: Mark S. Miller,
2026: Martin Hassman,
2027: Mohamed Zergaoui,
1.359 avankest 2028: Ms2ger,
1.360 avankest 2029: Odin Hørthe Omdal,
1.343 avankest 2030: Olli Pettay,
2031: Pawel Glowacki,
2032: Peter Michaux,
2033: Philip Taylor,
2034: Robin Berjon,
2035: Rune Halvorsen,
2036: Ruud Steltenpool,
2037: Sergiu Dumitriu,
1.360 avankest 2038: Sigbjørn Finne,
1.343 avankest 2039: Simon Pieters,
2040: Stewart Brodie,
2041: Sunava Dutta,
2042: Thomas Roessler,
2043: Tom Magliery, and
2044: Zhenbin Xu
2045:
2046: for their contributions to this specification.</p>
2047:
2048: <p>Special thanks to the Microsoft employees who first implemented the
2049: <code title="">XMLHttpRequest</code> interface, which was first widely
2050: deployed by the Windows Internet Explorer browser.</p>
1.2 avankest 2051:
1.56 avankest 2052: <p>Special thanks also to the WHATWG for drafting an initial version of
1.343 avankest 2053: this specification in their Web Applications 1.0 document (now renamed to
2054: HTML). <a href="#refsHTML">[HTML]</a></p>
1.2 avankest 2055:
2056: <p>Thanks also to all those who have helped to improve this specification
1.343 avankest 2057: by sending suggestions and corrections. (Please, keep bugging us with your
2058: issues!)</p>
2059:
2060:
Webmaster