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