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