Annotation of 2006/webapi/XMLHttpRequest/Overview.src.html, revision 1.80
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">
6: pre.idl { border:solid thin; background:#eee; color:#000; padding:0.5em }
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 }
10: p.note { margin-left:2em; font-weight:bold; font-style:italic; color:#008000 }
11: p.note::before { content:"Note: " }
12: p.issue { padding:.5em; border:solid #f00 }
13: p.issue::before { content:"Issue: " }
14: em.ct { text-transform:lowercase; font-variant:small-caps; font-style:normal }
15: dfn { font-weight:bold; font-style:normal }
16: code { color:orangered }
17: code :link, code :visited { color:inherit }
18: </style>
1.7 avankest 19: <link rel="stylesheet" href="http://www.w3.org/StyleSheets/TR/base">
1.58 avankest 20: <!--<link rel="stylesheet" href="http://www.w3.org/StyleSheets/TR/W3C-WD">-->
1.1 avankest 21: </head>
22: <body>
23: <div class="head">
24: <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 25:
1.10 avankest 26: <h1 class="head">The <code title="">XMLHttpRequest</code> Object</h1>
1.12 avankest 27:
1.53 avankest 28: <h2 class="no-num no-toc" id="pagesubtitle">Editor's draft<!--W3C Working Draft--> [DATE: 3 August 2002]</h2>
1.12 avankest 29:
1.1 avankest 30: <dl>
1.10 avankest 31: <dt>This Version:</dt>
1.24 avankest 32:
1.47 avankest 33: <dd><a href="[VERSION]/">http://www.w3.org/TR/[YEAR]/WD-XMLHttpRequest-[CDATE]/</a></dd>
1.14 avankest 34:
1.10 avankest 35: <dt>Latest Version:</dt>
1.24 avankest 36:
1.1 avankest 37: <dd><a href="http://www.w3.org/TR/XMLHttpRequest/">http://www.w3.org/TR/XMLHttpRequest/</a></dd>
1.14 avankest 38:
1.10 avankest 39: <dt>Previous Versions:</dt>
1.24 avankest 40:
1.58 avankest 41: <dd><a href="http://www.w3.org/TR/2007/WD-XMLHttpRequest-20070227/">http://www.w3.org/TR/2007/WD-XMLHttpRequest-20070227/</a></dd>
42:
1.22 avankest 43: <dd><a href="http://www.w3.org/TR/2006/WD-XMLHttpRequest-20060927/">http://www.w3.org/TR/2006/WD-XMLHttpRequest-20060927/</a></dd>
1.24 avankest 44:
1.1 avankest 45: <dd><a href="http://www.w3.org/TR/2006/WD-XMLHttpRequest-20060619/">http://www.w3.org/TR/2006/WD-XMLHttpRequest-20060619/</a></dd>
1.24 avankest 46:
1.1 avankest 47: <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 48:
1.1 avankest 49: <dt>Editor:</dt>
1.24 avankest 50:
1.1 avankest 51: <dd><a href="http://annevankesteren.nl/">Anne van Kesteren</a>
52: (<a href="http://www.opera.com/">Opera Software ASA</a>)
53: <<a href="mailto:annevk@opera.com">annevk@opera.com</a>></dd>
54: </dl>
1.14 avankest 55:
1.1 avankest 56: <p class="copyright"><a href="http://www.w3.org/Consortium/Legal/ipr-notice#Copyright">Copyright</a>
1.51 avankest 57: © 2007
58: <a href="http://www.w3.org/"><acronym title="World Wide Web Consortium">W3C</acronym></a><sup>®</sup>
59: (<a href="http://www.csail.mit.edu/"><acronym title="Massachusetts Institute of Technology">MIT</acronym></a>,
60: <a href="http://www.ercim.org/"><acronym title="European Research Consortium for Informatics and Mathematics">ERCIM</acronym></a>,
61: <a href="http://www.keio.ac.jp/">Keio</a>), All Rights Reserved. W3C
62: <a href="http://www.w3.org/Consortium/Legal/ipr-notice#Legal_Disclaimer">liability</a>,
63: <a href="http://www.w3.org/Consortium/Legal/ipr-notice#W3C_Trademarks">trademark</a>
64: and
65: <a href="http://www.w3.org/Consortium/Legal/copyright-documents">document
66: use</a> rules apply.</p>
1.1 avankest 67: </div>
1.12 avankest 68:
1.1 avankest 69: <hr>
1.12 avankest 70:
1.1 avankest 71: <h2 class="no-num no-toc" id="specabstract">Abstract</h2>
1.10 avankest 72:
1.22 avankest 73: <p>The <code title="">XMLHttpRequest</code> Object specification defines an
74: <abbr title="Application Programming Interface">API</abbr> that provides
75: scripted client functionality for transferring data between a client and a
76: server.</p>
1.12 avankest 77:
1.1 avankest 78: <h2 class="no-num no-toc" id="sotd">Status of this Document</h2>
1.12 avankest 79:
1.1 avankest 80: <p><em>This section describes the status of this document at the time of its
1.36 avankest 81: publication. Other documents may supersede this document. A list of current
82: W3C publications and the latest revision of this technical report can be
83: found in the <a href="http://www.w3.org/TR/">W3C technical reports index</a>
84: at http://www.w3.org/TR/.</em></p>
85:
1.63 avankest 86: <!-- change back to Last Call -->
87: <p>This is the [DATE: 3 August 2002] <strong>Editor's</strong> Working
1.54 avankest 88: Draft of The <code title="">XMLHttpRequest</code> Object specification.
1.47 avankest 89: Please send comments to
90: <a href="mailto:public-webapi@w3.org">public-webapi@w3.org</a>
91: (<a href="http://lists.w3.org/Archives/Public/public-webapi/">archived</a>)
92: with either <samp>[XHR]</samp> or <samp title="">[XMLHttpRequest]</samp> at
1.63 avankest 93: the start of the subject line<!-- by 2 April 2007-->.</p>
1.51 avankest 94:
1.47 avankest 95: <p>This document is produced by the
96: <a href="http://www.w3.org/2006/webapi/">Web API Working Group</a>, part of
97: the <a href="http://www.w3.org/2006/rwc/Activity">Rich Web Clients
98: Activity</a> in the W3C <a href="http://www.w3.org/Interaction/">Interaction
1.51 avankest 99: Domain</a>. Changes made to this document can be found in the
1.47 avankest 100: <a href="http://dev.w3.org/cvsweb/2006/webapi/XMLHttpRequest/Overview.html">W3C
101: public CVS server</a>.</p>
1.12 avankest 102:
1.1 avankest 103: <p>Publication as a Working Draft does not imply endorsement by the W3C
1.36 avankest 104: Membership. This is a draft document and may be updated, replaced or
105: obsoleted by other documents at any time. It is inappropriate to cite this
106: document as other than work in progress.</p>
1.12 avankest 107:
1.1 avankest 108: <p>This document was produced by a group operating under the
1.36 avankest 109: <a href="http://www.w3.org/Consortium/Patent-Policy-20040205/">5 February
1.52 avankest 110: 2004 W3C Patent Policy</a>. W3C maintains a
1.36 avankest 111: <a rel="disclosure" href="http://www.w3.org/2004/01/pp-impl/38482/status">public
112: list of any patent disclosures</a> made in connection with the deliverables
113: of the group; that page also includes instructions for disclosing a patent.
114: An individual who has actual knowledge of a patent which the individual
115: believes contains
116: <a href="http://www.w3.org/Consortium/Patent-Policy-20040205/#def-essential">Essential
117: Claim(s)</a> must disclose the information in accordance with
118: <a href="http://www.w3.org/Consortium/Patent-Policy-20040205/#sec-Disclosure">section
119: 6 of the W3C Patent Policy</a>.</p>
1.12 avankest 120:
1.1 avankest 121: <h2 class="no-num no-toc" id="toc">Table of Contents</h2>
1.21 avankest 122:
1.1 avankest 123: <!--toc-->
1.12 avankest 124:
1.1 avankest 125: <h2 id="introduction">Introduction</h2>
1.12 avankest 126:
1.1 avankest 127: <p><em>This section is non-normative.</em></p>
1.12 avankest 128:
1.33 avankest 129: <p>The <code>XMLHttpRequest</code> object implements an interface exposed by
130: a scripting engine that allows scripts to perform HTTP client functionality,
1.22 avankest 131: such as submitting form data or loading data from a server.</p>
1.24 avankest 132:
1.1 avankest 133: <p>The name of the object is <code>XMLHttpRequest</code> for compatibility
1.22 avankest 134: with the web, though each component of this name is potentially misleading.
1.39 avankest 135: First, the object supports any text based format, including XML. Second, it
136: can be used to make requests over both HTTP and HTTPS (some implementations
137: support protocols in addition to HTTP and HTTPS, but that functionality is
138: not covered by this specification). Finally, it supports "requests" in a
139: broad sense of the term as it pertains to HTTP; namely all activity involved
140: with HTTP requests or responses for the defined HTTP methods.</p>
1.12 avankest 141:
1.1 avankest 142: <h3 id="examples">Examples of Usage</h3>
1.12 avankest 143:
1.1 avankest 144: <p><em>This section is non-normative.</em></p>
1.12 avankest 145:
1.37 avankest 146: <p>Some [<cite><span>ECMAScript</span></cite>] examples
1.32 avankest 147: are listed in the specification. In addition, you can find some below.</p>
1.14 avankest 148:
149: <div class="example">
150: <p>Some simple code to do something with data from an XML document fetched
1.22 avankest 151: over the network:</p>
1.16 avankest 152:
1.58 avankest 153: <pre><code>function test(data) {
1.14 avankest 154: // taking care of data
155: }
156:
157: function handler() {
158: if(this.readyState == 4 && this.status == 200) {
159: // so far so good
160: if(this.responseXML != null && this.responseXML.getElementById('test').firstChild.data)
161: // success!
162: test(this.responseXML.getElementById('test').firstChild.data);
163: else
164: test(null);
165: } else if (this.readyState == 4 && this.status != 200) {
166: // fetched the wrong page or network error...
167: test(null);
168: }
169: }
1.12 avankest 170:
1.14 avankest 171: var client = new XMLHttpRequest();
172: client.onreadystatechange = handler;
173: client.open("GET", "test.xml");
1.58 avankest 174: client.send();</code></pre>
1.16 avankest 175:
1.56 avankest 176: <p>If you just want to log a message to the server:</p>
1.16 avankest 177:
1.58 avankest 178: <pre><code>function log(message) {
1.14 avankest 179: var client = new XMLHttpRequest();
1.56 avankest 180: client.open("POST", "/log");
1.57 avankest 181: client.setRequestHeader("Content-Type", "text/plain;charset=UTF-8");
1.14 avankest 182: client.send(message);
1.58 avankest 183: }</code></pre>
1.16 avankest 184:
1.14 avankest 185: <p>Or if you want to check the status of a document on the server:</p>
1.16 avankest 186:
1.58 avankest 187: <pre><code>function fetchStatus(address) {
1.14 avankest 188: var client = new XMLHttpRequest();
189: client.onreadystatechange = function() {
190: // in case of network errors this might not give reliable results
191: if(this.readyState == 4)
192: returnStatus(this.status);
193: }
194: client.open("HEAD", address);
195: client.send();
1.58 avankest 196: }</code></pre>
1.14 avankest 197: </div>
1.12 avankest 198:
1.1 avankest 199: <h3 id="conformance">Conformance</h3>
1.12 avankest 200:
1.27 avankest 201: <p>Everything in this specification is normative except for diagrams,
202: examples, notes and sections marked non-normative.</p>
1.12 avankest 203:
1.1 avankest 204: <p>The key words <em class="ct">must</em>, <em class="ct">must not</em>,
1.74 avankest 205: <em class="ct">should</em> and <em class="ct">may</em> in this document are
206: to be interpreted as described in RFC 2119.
207: [<cite><span>RFC2119</span></cite>]</p>
1.12 avankest 208:
1.1 avankest 209: <p>This specification defines the following classes of products:</p>
1.12 avankest 210:
1.1 avankest 211: <dl>
1.74 avankest 212: <dt><dfn id="conforming-user-agent">Conforming user agent</dfn></dt>
1.24 avankest 213:
1.74 avankest 214: <dd>
215: <p>A user agent <em class="ct">must</em> behave as described in this
216: specification in order to be considered conformant even when faced with
217: non-conforming scripts.</p>
218:
1.75 avankest 219: <p>User agents <em class="ct">may</em> optimize any algorithm given in
220: this specification, so long as the end result is indistinguishable from
221: the result that would be obtained by the specification's algorithms. (The
222: algorithms in this specification are generally written with more concern
223: for clarity than efficiency.)</p>
1.74 avankest 224: </dd>
1.24 avankest 225:
1.74 avankest 226: <dt><dfn id="conforming-script">Conforming script</dfn></dt>
1.24 avankest 227:
1.74 avankest 228: <dd><p>A script <em class="ct">must</em> satisfy the constraints and
229: conditions described by this specification in order to be
230: conformant.</p></dd>
1.1 avankest 231: </dl>
1.32 avankest 232:
1.30 avankest 233: <h4 id="dependencies">Dependencies</h4>
1.33 avankest 234:
1.29 avankest 235: <p>This specification relies on several underlying specifications.</p>
236: <dl>
237: <dt>DOM</dt>
1.33 avankest 238:
1.29 avankest 239: <dd>
240: <p>Implementations <em class="ct">must</em> support some version of DOM
1.37 avankest 241: Events because this specification uses some of the features defined in
242: that specification. [<cite><span>DOM3Events</span></cite>]</p>
1.39 avankest 243:
1.37 avankest 244: <p>Implementations <em class="ct">must</em> support some version of DOM
245: Core because this specification uses some of the features defined in that
246: specification. [<cite><span>DOM3Core</span></cite>]</p>
1.29 avankest 247:
248: <p>Implementations <em class="ct">must</em> support some version of the
1.37 avankest 249: Window Object because some of the functionality in this specification
250: relies on it. [<cite><span>Window</span></cite>]</p>
1.29 avankest 251: </dd>
252:
253: <dt>HTTP</dt>
1.33 avankest 254:
1.29 avankest 255: <dd>
1.39 avankest 256: <p>Implementations <em class="ct">must</em> support some version of the
1.58 avankest 257: HTTP protocol. The user agent <em class="ct">should</em> support any HTTP
258: method that matches the <span><code>Method</code> production</span> and
1.73 avankest 259: <em class="ct">must</em> at least support the following methods:</p>
1.58 avankest 260:
261: <ul>
262: <li><code>GET</code></li>
263: <li><code>POST</code></li>
264: <li><code>HEAD</code></li>
265: <li><code>PUT</code></li>
266: <li><code>DELETE</code></li>
267: <li><code>OPTIONS</code></li>
268: </ul>
269:
270: <p>Other requirements regarding HTTP are made throughout the
1.39 avankest 271: specification. [<cite><span>RFC2616</span></cite>]</p>
1.29 avankest 272: </dd>
1.41 avankest 273:
274: <dt>XML</dt>
275:
276: <dd>
1.64 avankest 277: <p>Implementations <em class="ct">should</em> support some version of XML.
278: If they don't support some version of XML <code>responseXML</code>
1.41 avankest 279: <em class="ct">must</em> always be <code>null</code>.
280: [<cite><span>XML</span></cite>] [<cite><span>XMLNS</span></cite>]</p>
281: </dd>
1.29 avankest 282: </dl>
1.12 avankest 283:
1.80 ! avankest 284: <h4 id="terminology">Terminology</h4>
1.12 avankest 285:
1.80 ! avankest 286: <p>There is a <dfn id="case-insensitive-match">case-insensitive match</dfn>
! 287: of strings <var>a</var> and <var>b</var> if after lowercasing both strings
! 288: (by mapping A-Z to a-z) they are identical.</p>
! 289:
! 290: <h4 id="extensibility">Extensibility</h4>
1.12 avankest 291:
1.25 avankest 292: <p>Extensions of the APIs defined by this specification are <em>strongly
1.22 avankest 293: discouraged</em>. User agents, Working Groups and other interested parties
1.33 avankest 294: should discuss extensions on a relevant public forum, preferably
1.22 avankest 295: <a href="mailto:public-webapi@w3.org">public-webapi@w3.org</a>.</p>
1.12 avankest 296:
297: <h2 id="xmlhttprequest">The <code title="">XMLHttpRequest</code> Object</h2>
298:
1.58 avankest 299: <p>The <code>XMLHttpRequest</code> object can be used by scripts to
1.22 avankest 300: programmatically connect to their originating server via HTTP.</p>
1.12 avankest 301:
1.1 avankest 302: <p>Objects implementing the <code>XMLHttpRequest</code> interface
1.22 avankest 303: <em class="ct">must</em> also implement the <code>EventTarget</code>
1.58 avankest 304: interface. [<cite><span>DOM3Events</span></cite>]</p>
1.12 avankest 305:
1.58 avankest 306: <p>Objects implementing the <code title="">Window</code> interface
307: <em class="ct">must</em> provide an <code title="">XMLHttpRequest()</code>
308: constructor. [<cite><span>Window</span></cite>]</p>
1.12 avankest 309:
1.1 avankest 310: <div class="example">
1.58 avankest 311: <p>In ECMAScript this can be used as follows:</p>
312: <!-- [<cite><span>ECMAScript</span></cite>] -->
313:
314: <pre><code>var client = new XMLHttpRequest();</code></pre>
1.1 avankest 315: </div>
1.12 avankest 316:
1.58 avankest 317: <p>When the <code title="">XMLHttpRequest()</code> constructor is invoked a
318: persistent pointer to the associated <code title="">Window</code> object
319: <em class="ct">must</em> be stored on the newly created object. This is the
1.25 avankest 320: <dfn title="Window pointer" id="window-pointer"><code>Window</code>
1.58 avankest 321: pointer</dfn>. The associated <code title="">Window</code> object is the one
322: of which the <code title="">XMLHttpRequest</code> constructor was
323: invoked. This <span title="Window pointer">pointer</span>
1.25 avankest 324: <em class="ct">must</em> persist even if the browsing context in which the
1.37 avankest 325: <code title="">Window</code> is located is destroyed (by removing it from a
326: parent browsing context, for instance).</p>
1.25 avankest 327:
1.37 avankest 328: <p>The term browsing context is defined by the <cite>Window Object
329: 1.0</cite> specification. [<cite><span>Window</span></cite>]</p>
1.27 avankest 330:
331: <!-- XXX if the document object changes in the browsing context you get an
1.33 avankest 332: exception in some implementations. -->
1.27 avankest 333:
1.58 avankest 334: <div class="example">
1.65 avankest 335: <p>If <var><code>win</code></var> is a <code title="">Window</code> object
336: <var><code>client</code></var> will have a pointer to
337: <var><code>win</code></var> in the following example:</p>
1.58 avankest 338:
1.65 avankest 339: <pre><code>var client = new win.XMLHttpRequest()</code></pre>
1.58 avankest 340: </div>
1.12 avankest 341:
1.58 avankest 342: <pre class="idl">interface <dfn id="xmlhttprequest-object">XMLHttpRequest</dfn> {
343: // event handler
1.70 avankest 344: attribute EventListener <span>onreadystatechange</span>;
1.58 avankest 345:
346: // state
1.71 avankest 347: const unsigned short <span title="UNSENT state">UNSENT</span> = 0;
1.58 avankest 348: const unsigned short <span title="OPEN state">OPEN</span> = 1;
349: const unsigned short <span title="SENT state">SENT</span> = 2;
350: const unsigned short <span title="RECEIVING state">RECEIVING</span> = 3;
1.79 avankest 351: const unsigned short <span title="DONE state">DONE</span> = 4;
1.70 avankest 352: readonly attribute unsigned short <span>readyState</span>;
1.58 avankest 353:
354: // request
1.70 avankest 355: void <span>open</span>(in DOMString <var>method</var>, in DOMString <var>url</var>);
356: void <span>open</span>(in DOMString <var>method</var>, in DOMString <var>url</var>, in boolean <var>async</var>);
357: void <span>open</span>(in DOMString <var>method</var>, in DOMString <var>url</var>, in boolean <var>async</var>, in DOMString <var>user</var>);
358: void <span>open</span>(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>);
359: void <span>setRequestHeader</span>(in DOMString <var>header</var>, in DOMString <var>value</var>);
360: void <span>send</span>();
361: void <span>send</span>(in DOMString <var>data</var>);
362: void <span>send</span>(in Document <var>data</var>);
363: void <span>abort</span>();
1.58 avankest 364:
365: // response
1.70 avankest 366: DOMString <span>getAllResponseHeaders</span>();
367: DOMString <span>getResponseHeader</span>(in DOMString <var>header</var>);
368: readonly attribute DOMString <span>responseText</span>;
369: readonly attribute Document <span>responseXML</span>;
370: readonly attribute unsigned short <span>status</span>;
371: readonly attribute DOMString <span>statusText</span>;
1.1 avankest 372: };</pre>
1.8 avankest 373:
1.58 avankest 374: <p>The <code>XMLHttpRequest</code> object can be in five states:
1.71 avankest 375: <span title="UNSENT state">UNSENT</span>,
1.58 avankest 376: <span title="OPEN state">OPEN</span>, <span title="SENT state">SENT</span>,
377: <span title="RECEIVING state">RECEIVING</span> and
1.79 avankest 378: <span title="DONE state">DONE</span>. The current state is exposed through
379: the <code>readyState</code> attribute. The method definitions below define
380: when a state transition takes place.</p>
1.58 avankest 381:
382: <p>When constructed, the <code>XMLHttpRequest</code> object
1.71 avankest 383: <em class="ct">must</em> be in the UNSENT state. This state is represented
384: by the <dfn id="unsent" title="UNSENT state"><code>UNSENT</code></dfn>
1.58 avankest 385: constant, whose value is <code>0</code>.</p>
386:
387: <p>The OPEN state is the state of the object when the <code>open()</code>
388: method has been successfully invoked. During this state reqeust headers can
389: be set using <code>setRequestHeader()</code> and the request can be made
390: using <code>send()</code>. This state is represented by the
391: <dfn id="open" title="OPEN state"><code>OPEN</code></dfn> constant, whose
392: value is <code>1</code>.</p>
393:
394: <p>The SENT state is the state of the object when the user agent
395: successfully acknowledged the request. This state is represented by the
396: <dfn id="sent" title="SENT state"><code>SENT</code></dfn> constant, whose
397: value is <code>2</code>.</p>
398:
399: <p>The RECEIVING state is the state of the object when all HTTP headers have
400: been received. The object typically remains in this state until the complete
401: message body (if any) has been received. This state is represented by the
402: <dfn id="receiving" title="RECEIVING state"><code>RECEIVING</code></dfn>
403: constant, whose value is <code>3</code>.</p>
404:
1.79 avankest 405: <p>The DONE state is the state of the object when either the data transfer
1.58 avankest 406: has been completed or something went wrong during the transfer (infinite
407: redirects for instance). This state is represented by the
1.79 avankest 408: <dfn id="done" title="DONE state"><code>DONE</code></dfn> constant, whose
409: value is <code>4</code>.</p>
1.58 avankest 410:
1.5 avankest 411: <dl>
1.12 avankest 412:
1.39 avankest 413: <dt><dfn id="dfn-onreadystatechange"><code>onreadystatechange</code></dfn>
414: of type <code>EventListener</code></dt>
1.12 avankest 415:
1.1 avankest 416: <dd>
417: <p>An attribute that takes an <code>EventListener</code> as value that
1.58 avankest 418: <em class="ct">must</em> be invoked along with any other appropriate event
419: listeners that are registered on this object when a
420: <code>readystatechange</code> event is dispatched on it. Its initial value
421: <em class="ct">must</em> be <code>null</code>.</p>
1.1 avankest 422: </dd>
1.12 avankest 423:
1.1 avankest 424: <dt><dfn id="dfn-readystate"><code>readyState</code></dfn> of type
1.22 avankest 425: <code>unsigned short</code>, readonly</dt>
1.12 avankest 426:
1.1 avankest 427: <dd>
1.58 avankest 428: <p>The attribute <em class="ct">must</em> be the value of the constant
429: corresponding to the object's current state.</p>
1.1 avankest 430: </dd>
1.12 avankest 431:
1.14 avankest 432: <dt><dfn id="dfn-open" title="open"><code>open(<var>method</var>,
1.22 avankest 433: <var>url</var>, <var>async</var>, <var>user</var>,
434: <var>password</var>)</code></dfn>, method</dt>
1.12 avankest 435:
1.1 avankest 436: <dd>
1.58 avankest 437: <p>When invoked, the user agent <em class="ct">must</em> follow the
438: following steps:</p>
439:
440: <ol>
441: <li><p>If the <var>method</var> argument doesn't match the
442: <dfn><code>Method</code> production</dfn> defined in section 5.1.1 of RFC
443: 2616 the user agent <em class="ct">must</em> raise a
444: <code>SYNTAX_ERR</code> exception and abort these steps.
445: [<cite><span>RFC2616</span></cite>]</p></li>
446:
447: <li><p>If the given <var>method</var> is not supported for security
448: reasons the user agent <em class="ct">should</em> raise a
449: <code>SECURITY_ERR</code> exception and abort these steps.</p></li>
450:
451: <li><p>Let <var>stored method</var> be <var>method</var>.</p></li>
452:
1.80 ! avankest 453: <li><p>If <var>method</var>
! 454: <span title="case-insensitive match">case-insensitively matches</span>
! 455: <code>GET</code>, <code>POST</code>, <code>HEAD</code>, <code>PUT</code>,
1.58 avankest 456: <code>DELETE</code> or <code>OPTIONS</code> the user agent
1.80 ! avankest 457: <em class="ct">must</em> convert it to its uppercase equivalent (by
! 458: mapping a-z to A-Z) and let <var>stored method</var> be the
! 459: result.</p></li>
1.68 avankest 460: <!-- WebKit (and supposedly Firefox) also uppercase: CONNECT, COPY,
461: INDEX, LOCK, M-POST, MKCOL, MOVE, PROPFIND, PROPPATCH, TRACE and UNLOCK.
462: Not sure if TRACE and CONNECT are worth it though. They raise a
463: SECURITY_ERR exception anyway... -->
1.58 avankest 464:
465: <li><p>Drop the fragment identifier (if any) from <var>url</var> and let
466: <var>stored url</var> be the result of that operation.</p></li>
467:
468: <li><p>If <var>stored url</var> is a relative reference it
469: <em class="ct">must</em> be resolved using the current value of the
470: <code>baseURI</code> attribute of the <code>Document</code> object
471: currently associated with the <span><code>Window</code> pointer</span>.
472: If this fails the user agent <em class="ct">must</em> raise a
473: <code>SYNTAX_ERR</code> exception and abort these steps.</p></li>
474:
475: <li><p>If the <code>"user:password"</code> format in the
476: <code>userinfo</code> production defined in section 3.2.1 of RFC 3986 is
477: not supported for the relevant scheme and <var>stored url</var> contains
478: this format the user agent <em class="ct">must</em> throw a
1.69 avankest 479: <code>SYNTAX_ERR</code> and abort these steps.
480: [<cite><span>RFC3986</span></cite>]</p></li>
1.58 avankest 481:
482: <li><p>If <var>stored url</var> contains the <code>"user:password"</code>
483: format let <var>stored user</var> be the user part and <var>stored
484: password</var> be the password part.</p></li>
485:
486: <li><p>If <var>stored url</var> just contains the <code>"user"</code>
487: format let <var>stored user</var> be the user part.</p></li>
488:
1.69 avankest 489: <li>
490: <p>If <var>stored url</var> is non same-origin the user agent
491: <em class="ct">should</em> raise a <code>SECURITY_ERR</code> exception
492: and abort these steps.</p>
493: <p class="note">This specification does not define what constitutes as
1.71 avankest 494: non same-origin.<!-- XXX reference HTML5? --></p>
1.69 avankest 495: </li>
1.58 avankest 496:
497: <li><p>Let <var>async</var> be the value of the <var>async</var> argument
498: or <code>false</code> if it was omitted.</p></li>
499:
500: <li><p>If the <var>user</var> argument was not omitted and its syntax
501: does not match that specified by the relevant authentication scheme the
502: user agent <em class="ct">must</em> raise a <code>SYNTAX_ERR</code>
503: exception and abort these steps.</p></li>
1.14 avankest 504:
1.58 avankest 505: <li>
506: <p>If the <var>user</var> argument was not omitted and is not
507: <code>null</code> let <var>stored user</var> be <var>user</var> encoded
508: using the encoding specified in the relevant authentication scheme or
509: UTF-8 if the scheme fails to specify an encoding.</p>
1.14 avankest 510:
1.58 avankest 511: <p class="note">This step overrides any user that may have been set by
512: the <var>url</var> argument.</p>
513: </li>
1.16 avankest 514:
1.58 avankest 515: <li><p>If the <var>user</var> argument was not omitted and is
516: <code>null</code> remove <var>stored user</var>.</p></li>
1.14 avankest 517:
1.58 avankest 518: <li><p>If the <var>password</var> argument was not omitted and its syntax
519: does not match that specified by the relevant authentication scheme the
520: user agent <em class="ct">must</em> raise a <code>SYNTAX_ERR</code>
521: exception and abort these steps.</p></li>
522:
523: <li><p>If the <var>password</var> argument was not omitted and is not
524: <code>null</code> let <var>stored password</var> be <var>password</var>
525: encoded using the encoding specified in the relevant authentication
526: scheme or UTF-8 if the scheme fails to specify an encoding.</p></li>
527:
528: <li><p>If the <var>password</var> argument was not omitted and is
529: <code>null</code> remove <var>stored password</var>.</p></li>
530:
531: <li><p>Set <code>responseText</code>, <code>responseXML</code>,
532: <code>status</code> and <code>statusText</code> to their initial
533: values and reset the list of request headers.<p></li>
534:
1.60 avankest 535: <li><p>Any network activity for which the object responsible
536: <em class="ct">should</em> be cancelled.</p></li>
1.58 avankest 537: <!-- we can hardly require it... -->
538:
539: <li><p>Switch the object to the <span title="OPEN state">OPEN</span>
540: state; the user agent <em class="ct">must</em> then synchronously
541: dispatch a <code>readystatechange</code> event on the object and abort
542: these steps (returning the method call).</p></li>
543: </ol>
1.14 avankest 544:
1.19 avankest 545: <p class="note">A future version or extension of this specification will
1.33 avankest 546: most likely define a way of doing cross-site requests.</p>
1.1 avankest 547: </dd>
1.12 avankest 548:
1.14 avankest 549: <dt><dfn id="dfn-setrequestheader" title="setrequestheader"><code>setRequestHeader(<var>header</var>,
1.22 avankest 550: <var>value</var>)</code></dfn>, method</dt>
1.12 avankest 551:
1.5 avankest 552: <dd>
1.45 avankest 553: <p>Each request has a list of request headers with associated values. This
554: method can be used to manipulate those values and set new request
555: headers.</p>
556:
1.58 avankest 557: <p>When invoked, the user agent <em class="ct">must</em> follow the
558: following steps:</p>
1.14 avankest 559:
1.58 avankest 560: <ol>
561: <li><p>If the state of the object is not
562: <span title="OPEN state">OPEN</span> the user agent
563: <em class="ct">must</em> raise an <code>INVALID_STATE_ERR</code>
564: exception and abort these steps.</p></li>
565:
566: <li><p>If the <span><code>send()</code> flag</span> is set the user agent
567: <em class="ct">must</em> raise an <code>INVALID_STATE_ERR</code>
568: exception and abort these steps.</p></li>
1.14 avankest 569:
1.58 avankest 570: <li><p>If the <var>header</var> argument doesn't match the
1.22 avankest 571: <dfn><code>field-name</code> production</dfn> as defined by section 4.2
1.70 avankest 572: of RFC 2616 or is <code>null</code> the user agent
1.72 avankest 573: <em class="ct">must</em> raise a <code>SYNTAX_ERR</code> exception and
574: abort these steps. [<cite><span>RFC2616</span></cite>]</p></li>
1.70 avankest 575:
576: <li><p>If the <var>value</var> argument is <code>null</code> the user
577: agent <em class="ct">must</em> abort these steps. (Don't raise an
578: exception.)</li>
579: <!-- undefined is to be treated as null here... -->
1.79 avankest 580:
1.58 avankest 581: <li><p>If the <var>value</var> argument doesn't match the
1.22 avankest 582: <dfn><code>field-value</code> production</dfn> as defined by section 4.2
1.58 avankest 583: of RFC 2616 the user agent <em class="ct">must</em> raise a
584: <code>SYNTAX_ERR</code> and abort these steps.
585: [<cite><span>RFC2616</span></cite>]</p></li>
1.14 avankest 586:
1.32 avankest 587: <li>
1.58 avankest 588: <p>For security reasons these steps <em class="ct">should</em> be
1.80 ! avankest 589: aborted if the <var>header</var> argument
! 590: <span title="case-insensitive match">case-insensitively matches</span>
! 591: one of the following headers:</p>
1.58 avankest 592:
1.32 avankest 593: <ul>
594: <li><code>Accept-Charset</code></li>
595: <li><code>Accept-Encoding</code></li>
1.68 avankest 596: <li><code>Connection</code></li>
1.32 avankest 597: <li><code>Content-Length</code></li>
1.68 avankest 598: <li><code>Content-Transfer-Encoding</code></li>
599: <li><code>Date</code></li>
1.32 avankest 600: <li><code>Expect</code></li>
601: <li><code>Host</code></li>
602: <li><code>Keep-Alive</code></li>
603: <li><code>Referer</code></li>
604: <li><code>TE</code></li>
605: <li><code>Trailer</code></li>
606: <li><code>Transfer-Encoding</code></li>
607: <li><code>Upgrade</code></li>
1.68 avankest 608: <li><code>Via</code></li>
1.32 avankest 609: </ul>
610: </li>
1.5 avankest 611:
1.59 avankest 612: <!--
1.58 avankest 613: <li>
614: <p>If the <var>header</var> argument case-insensitively matches one of
615: the following headers the user agent <em class="ct">must</em> set the
616: value of that HTTP header to <var>value</var> and abort these steps:</p>
1.14 avankest 617:
1.58 avankest 618: <ul>
619: <li><code>Apply-To-Redirect-Ref</code></li>
620: <li><code>Authorization</code></li>
621: <li><code>C-Ext</code></li>
622: <li><code>Content-Base</code></li>
623: <li><code>Content-Location</code></li>
624: <li><code>Content-MD5</code></li>
625: <li><code>Content-Range</code></li>
626: <li><code>Content-Type</code></li>
627: <li><code>Content-Version</code></li>
628: <li><code>Cookie</code></li>
629: <li><code>Cookie2</code></li>
630: <li><code>Delta-Base</code></li>
631: <li><code>Depth</code></li>
632: <li><code>Destination</code></li>
633: <li><code>ETag</code></li>
634: <li><code>Ext</code></li>
635: <li><code>From</code></li>
636: <li><code>If</code></li>
637: <li><code>If-Modified-Since</code></li>
638: <li><code>If-Range</code></li>
639: <li><code>If-Unmodified-Since</code></li>
640: <li><code>Label</code></li>
641: <li><code>Lock-Token</code></li>
642: <li><code>Max-Forwards</code></li>
643: <li><code>MIME-Version</code></li>
644: <li><code>Ordering-Type</code></li>
645: <li><code>Overwrite</code></li>
646: <li><code>Proxy-Authorization</code></li>
647: <li><code>Redirect-Ref</code></li>
648: <li><code>SOAPAction</code></li>
649: <li><code>Status-URI</code></li>
650: <li><code>Timeout</code></li>
651: </ul>
652: </li>
1.59 avankest 653: -->
1.44 avankest 654:
1.58 avankest 655: <li><p>If the <var>header</var> argument is not in the list of request
656: headers the user agent <em class="ct">must</em> append the
657: <var>header</var> with its associated <var>value</var> to the list and
658: abort these steps.</p></li>
659:
660: <li><p>If the <var>header</var> argument is in the list of request
661: headers the user agent <em class="ct">must</em> either use multiple
662: headers, combine the values or use a combination of those (section 4.2,
1.66 avankest 663: RFC 2616). [<cite><span>RFC2616</span></cite>]</p></li>
1.58 avankest 664: </ol>
1.45 avankest 665:
666: <p class="note">See also the <code>send()</code> method regarding user
1.71 avankest 667: agent header handling for caching, authentication, proxies, and
668: cookies.</p>
1.14 avankest 669:
670: <div class="example">
1.58 avankest 671: <pre><code>// The following script:
1.14 avankest 672: var client = new XMLHttpRequest();
673: client.open('GET', 'demo.cgi');
674: client.setRequestHeader('X-Test', 'one');
675: client.setRequestHeader('X-Test', 'two');
676: client.send();
677:
678: // ...would result in the following header being sent:
679: ...
680: X-Test: one, two
1.58 avankest 681: ...</code></pre>
1.14 avankest 682: </div>
1.5 avankest 683: </dd>
1.12 avankest 684:
1.14 avankest 685: <dt><dfn id="dfn-send" title="send"><code>send(<var>data</var>)</code></dfn>,
1.22 avankest 686: method</dt>
1.12 avankest 687:
1.17 avankest 688: <dd>
1.58 avankest 689: <p>The <code>send()</code> method initiates the request and its optional
690: argument <em class="ct">may</em> be used by scripts to provide the entity
691: body. When the argument is provided scripts <em class="ct">should</em>
692: ensure that they have specified (before invoking <code>send()</code>) the
1.60 avankest 693: <code>Content-Type</code> header via <code>setRequestHeader()</code>.</p>
1.58 avankest 694:
695: <p>When invoked, the user agent <em class="ct">must</em> follow the
696: following steps:</p>
697:
698: <ol>
699: <li><p>If the state of the object is not
700: <span title="OPEN state">OPEN</span> the user agent
701: <em class="ct">must</em> raise an <code>INVALID_STATE_ERR</code>
702: exception and abort these steps.</p></li>
703:
704: <li><p>If the <span><code>send()</code> flag</span> is set the user agent
705: <em class="ct">must</em> raise an <code>INVALID_STATE_ERR</code>
706: exception and abort these steps.</p></li>
707:
708: <li>
709: <p>If the <var>data</var> argument has not been omitted and is not
710: <code>null</code> it <em class="ct">must</em> be used for the
711: <dfn id="dfn-entity-body">entity body</dfn> as defined by section 7.2 of
1.71 avankest 712: RFC 2616. [<cite><span>RFC2616</span></cite>]</p>
713:
714: <p>The following rules <em class="ct">must</em> be followed by the user
715: agent:</p>
1.58 avankest 716:
717: <dl>
718: <dt><var>data</var> is a <code>DOMString</code></dt>
719:
1.78 avankest 720: <dd><p><var>data</var> <em class="ct">must</em> be encoded as UTF-8 for
721: transmission.</p></dd>
1.58 avankest 722:
723: <dt><var>data</var> is a <code>Document</code>
724:
725: <dd>
726: <p><var>data</var> <em class="ct">must</em> be serialized into a
727: namespace well-formed XML document and encoded using the encoding
728: given by <code><var>data</var>.xmlEncoding</code>, if specified, or
729: UTF-8 otherwise. If this fails because the <code>Document</code>
730: cannot be serialized the user agent <em class="ct">must</em> act as if
731: <var>data</var> was <code>null</code>.</p>
732:
733: <p>If no <code>Content-Type</code> header has been set by the script
1.71 avankest 734: the user agent <em class="ct">must</em> append it to the list of
1.58 avankest 735: request headers with a value of <code>application/xml</code>.</p>
736:
737: <p class="note">Subsequent changes to the <code>Document</code> have
738: no effect on what is submitted.</p>
739: </dd>
740:
741: <dt><var>data</var> is not a <code>DOMString</code> or
742: <code>Document</code></dt>
743:
1.78 avankest 744: <dd><p>The stringification mechanisms of the host language
1.58 avankest 745: <em class="ct">must</em> be used on <var>data</var> and the result
746: <em class="ct">must</em> be treated as if <var>data</var> is a
1.78 avankest 747: <code>DOMString</code>.</p></dd>
748: <!-- XXX What if the host language doesn't have stringification for
749: each type? Do we care? -->
1.58 avankest 750: </dl>
751:
752: <p>If the data argument has been omitted or is <code>null</code> no
753: entity body <em class="ct">must</em> be used in the request.</p>
754: </li>
755:
1.71 avankest 756: <li><p>Make a request to <var>stored url</var>, using HTTP method
757: <var>stored method</var>, user <var>stored user</var> (if provided) and
758: password <var>stored password</var> (if provided), taking into account
759: the entity body, list of request headers and the rules listed directly
760: after this set of steps.</p></li>
1.60 avankest 761:
1.67 avankest 762: <li>
763: <p>The user agent <em class="ct">must</em> then synchronously
764: dispatch a <code>readystatechange</code> event on the object.</p>
765:
1.71 avankest 766: <p class="note">The state of the object doesn't actually change as the
1.67 avankest 767: event is dispatched for historical reasons.</p>
768: </li>
769:
1.58 avankest 770: <li><p>If <var>async</var> is <code>true</code> the user agent
771: <em class="ct">must</em> set the <dfn><code>send()</code> flag</dfn>,
772: directly unset it when the state changes and return the
773: <code>send()</code> method call. (Don't abort the steps in the algorithm
774: though.)</p></li>
775:
776: <li><p>If the request has been successfully acknowledged switch the
777: state to <span title="SENT state">SENT</span>; the user agent
778: <em class="ct">must</em> then synchronously dispatch a
779: <code>readystatechange</code> event on the object.</p></li>
1.67 avankest 780: <!-- IE does this regardless of the async value -->
1.58 avankest 781:
782: <li><p>If all HTTP headers have been receieved, immediately before
783: receiving the message body (if any), switch the state to
784: <span title="RECEIVING state">RECEIVING</span>; the user agent
785: <em class="ct">must</em> then synchronously dispatch a
786: <code>readystatechange</code> event on the object.</p></li>
1.67 avankest 787: <!-- IE does this regardless of the async value -->
1.58 avankest 788:
789: <li>
790: <p>If the response is an HTTP redirect (status code <code>301</code>,
791: <code>302</code>, <code>303</code> or <code>307</code>), then it
792: <em class="ct">must</em> be transparently followed (unless it violates
793: security, infinite loop precautions or the scheme isn't supported).</p>
1.60 avankest 794:
1.58 avankest 795: <p class="note">HTTP places requirements on the user agent regarding the
796: preservation of the request method and entity body during redirects, and
797: also requires users to be notified of certain kinds of automatic
798: redirections.</p>
799: <!-- Arguably HTTP should be fixed for the latter case. No browser
800: follows that as far as I know. -->
801: </li>
1.60 avankest 802:
1.58 avankest 803: <li>
804: <p>If something goes wrong (infinite loop, network errors) the user
805: agent <em class="ct">must</em> follow the following set of steps:</p>
1.60 avankest 806:
1.58 avankest 807: <ol>
808: <li><p>Set <code>responseText</code>, <code>responseXML</code>,
809: <code>status</code> and <code>statusText</code> to their initial
810: values and reset the list of request headers.</p></li>
1.60 avankest 811:
1.58 avankest 812: <li><p>Switch the state to
1.79 avankest 813: <span title="DONE state">DONE</span>.</p></li>
1.60 avankest 814:
1.58 avankest 815: <li><p>If <var>async</var> is set to <code>false</code> the user agent
816: <em class="ct">must</em> raise a <code>NETWORK_ERR</code> exception.
817: (Don't abort these steps.)</p></li>
1.60 avankest 818:
1.58 avankest 819: <li><p>Synchronously dispatch a <code>readystatechange</code> event on
820: the object.</p></li>
1.60 avankest 821:
1.58 avankest 822: <li><p>Abort the overall algorithm.</p></li>
823: </ol>
1.60 avankest 824:
1.58 avankest 825: <p class="note">In future versions of this specification the user agent
826: will be required to dispatch an <code>error</code> event if the above
827: occurs.</p>
828: </li>
829:
830: <li><p>When the request has successfully completed loading, switch the
1.79 avankest 831: state to <span title="DONE state">DONE</span>; the user agent
1.58 avankest 832: <em class="ct">must</em> then synchronously dispatch a
833: <code>readystatechange</code> event on the object and abort these
834: steps (and return the method call in case of <var>async</var> being
835: <code>false</code>).</p></li>
836: </ol>
1.14 avankest 837:
1.8 avankest 838: <p>If the user agent allows the specification of a proxy it
1.22 avankest 839: <em class="ct">should</em> modify the request appropriately;
1.42 avankest 840: <abbr title="in other words">i.e.</abbr>, connect to the proxy host
841: instead of the origin server, modify the <code>Request-Line</code> and
842: send <code>Proxy-Authorization</code> headers as specified.</p>
1.12 avankest 843:
1.42 avankest 844: <p>If the user agent supports HTTP Authentication it
1.22 avankest 845: <em class="ct">should</em> consider requests originating from this object
1.42 avankest 846: to be part of the protection space that includes the accessed URIs and
847: send <code>Authorization</code> headers and handle <code>401
1.72 avankest 848: Unauthorised</code> requests appropriately. If authentication fails, user
1.42 avankest 849: agents <em class="ct">should</em> prompt the users for credentials.
850: [<cite><span>RFC2617</span></cite>]</p>
851:
1.57 avankest 852: <p>If the user agent supports HTTP State Management it
1.42 avankest 853: <em class="ct">should</em> persist, discard and send cookies (as received
854: in the <code>Set-Cookie</code> and <code>Set-Cookie2</code> response
855: headers, and sent in the <code>Cookie</code> header) as applicable.
856: [<cite><span>RFC2965</span></cite>]</p>
857:
858: <p>If the user agent implements a HTTP cache it <em class="ct">should</em>
859: respect <code>Cache-Control</code> request headers set by the script
860: (<abbr title="for example">e.g.</abbr>, <code>Cache-Control:
861: no-cache</code> bypasses the cache). It <em class="ct">must not</em> send
862: <code>Cache-Control</code> or <code>Pragma</code> request headers
863: automatically unless the user explicitly requests such behaviour
864: (<abbr>e.g.</abbr>, by (force-)reloading the page). <code>304 Not
1.22 avankest 865: Modified</code> responses that are a result of a user agent generated
866: conditional request <em class="ct">must</em> be presented as <code>200
1.57 avankest 867: OK</code> responses with the appropriate content. The user agent
1.39 avankest 868: <em class="ct">must</em> allow scripts to override automatic cache
1.22 avankest 869: validation by setting request headers (e.g., <code>If-None-Match</code>,
1.42 avankest 870: <code>If-Modified-Since</code>), in which case <code>304 Not
871: Modified</code> responses <em class="ct">must</em> be passed through.
872: [<cite><span>RFC2616</span></cite>]</p>
1.12 avankest 873:
1.8 avankest 874: <p>If the user agent implements server-driven content-negotiation
1.42 avankest 875: it <em class="ct">should</em> set <code>Accept-Language</code>,
1.22 avankest 876: <code>Accept-Encoding</code> and <code>Accept-Charset</code> headers as
877: appropriate; it <em class="ct">must not</em> automatically set the
878: <code>Accept</code> header. Responses to such requests
1.40 avankest 879: <em class="ct">must</em> have the content-codings automatically
1.42 avankest 880: decoded. [<cite><span>RFC2616</span></cite>]</p>
1.8 avankest 881: </dd>
1.12 avankest 882:
1.14 avankest 883: <dt><dfn id="dfn-abort"><code>abort()</code></dfn>, method</dt>
1.12 avankest 884:
1.5 avankest 885: <dd>
1.60 avankest 886: <p>When invoked, the user agent <em class="ct">must</em> run the following
887: steps:</p>
888:
889: <ol>
890: <li><p>Set the <code>responseText</code>, <code>responseXML</code>,
891: <code>status</code> and <code>responseText</code> attributes to their
892: initial value as well as removing any registered request
893: headers.</p></li>
894:
895: <li><p>Any network activity for which the object responsible
896: <em class="ct">should</em> be cancelled.</p></li>
897:
1.79 avankest 898: <li><p>Switch the state to <span title="DONE state">DONE</span>; the user
899: agent <em class="ct">must</em> then synchronously dispatch a
900: <code>readystatechange</code> event on the object.</p></li>
1.67 avankest 901:
1.60 avankest 902: <li>
1.71 avankest 903: <p>Switch the state to <span title="UNSENT state">UNSENT</span>. (Don't
904: dispatch the <code>readystatechange</code> event.)</p>
1.60 avankest 905:
906: <p class="note">It's likely that a future version of the
907: <code>XMLHttpRequest</code> will dispatch an <code title="">abort</code>
908: event here.</p>
909: </li>
910: </ol>
1.5 avankest 911: </dd>
1.12 avankest 912:
1.14 avankest 913: <dt><dfn id="dfn-getallresponseheaders"><code>getAllResponseHeaders()</code></dfn>,
1.22 avankest 914: method</dt>
1.12 avankest 915:
1.5 avankest 916: <dd>
1.60 avankest 917: <p>When invoked, the user agent <em class="ct">must</em> run
1.58 avankest 918: the following steps:</p>
919:
920: <ol>
1.76 avankest 921: <li><p>If the state is not <span title="RECEIVING state">RECEIVING</span>
1.79 avankest 922: or <span title="DONE state">DONE</span> the user agent
1.58 avankest 923: <em class="ct">must</em> raise an <code>INVALID_STATE_ERR</code>
1.76 avankest 924: exception and abort these steps.</p></li>
1.58 avankest 925:
1.76 avankest 926: <li><p>The user agent <em class="ct">must</em> return all the HTTP
927: headers, as a single string, with each header line separated by a U+000D
928: CR U+000A LF pair excluding the status line.</p></li>
1.58 avankest 929: </ol>
1.24 avankest 930:
1.5 avankest 931: <div class="example">
1.58 avankest 932: <pre><code>// The following script:
1.5 avankest 933: var client = new XMLHttpRequest();
1.14 avankest 934: client.open("GET", "test.txt", true);
1.5 avankest 935: client.send();
1.12 avankest 936: client.onreadystatechange = function() {
1.13 avankest 937: if(this.readyState == 3) {
1.12 avankest 938: print(this.getAllResponseHeaders());
939: }
940: }
1.5 avankest 941:
942: // ...should output something similar to the following text:
943: Date: 2004年10月24日 04:58:38 GMT
944: Server: Apache/1.3.31 (Unix)
945: Keep-Alive: timeout=15, max=99
946: Connection: Keep-Alive
947: Transfer-Encoding: chunked
1.58 avankest 948: Content-Type: text/plain; charset=utf-8</code></pre>
1.5 avankest 949: </div>
950: </dd>
1.12 avankest 951:
1.18 avankest 952: <dt><dfn id="dfn-getresponseheader" title="getresponseheader"><code>getResponseHeader(<var>header</var>)</code></dfn>,
1.22 avankest 953: method</dt>
1.12 avankest 954:
1.1 avankest 955: <dd>
1.58 avankest 956: <p>When the method is invoked, the user agent <em class="ct">must</em> run
957: the following steps:</p>
1.14 avankest 958:
1.58 avankest 959: <ol>
1.76 avankest 960: <li><p>If the state is not <span title="RECEIVING state">RECEIVING</span>
1.79 avankest 961: or <span title="DONE state">DONE</span> the user agent
1.58 avankest 962: <em class="ct">must</em> raise an <code>INVALID_STATE_ERR</code>
1.76 avankest 963: exception and abort these steps.</p></li>
1.58 avankest 964:
1.76 avankest 965: <li><p>If the <var>header</var> argument doesn't match the
1.58 avankest 966: <span><code>field-name</code> production</span> the user agent
967: <em class="ct">must</em> raise a <code>SYNTAX_ERR</code> exception and
1.76 avankest 968: abort these steps.</p></li>
1.58 avankest 969:
1.80 ! avankest 970: <li><p>If the <var>header</var> argument
! 971: <span title="case-insensitive match">case-insensitively matches</span>
1.76 avankest 972: multiple HTTP headers for the last request sent the user agent
1.58 avankest 973: <em class="ct">must</em> return the values of these headers as a single
1.77 avankest 974: concatenated string separated from each other by an U+002C COMMA followed
1.76 avankest 975: by an U+0020 SPACE and abort these steps.</p></li>
1.58 avankest 976:
1.80 ! avankest 977: <li><p>If the <var>header</var> argument
! 978: <span title="case-insensitive match">case-insensitively matches</span> a
1.76 avankest 979: single HTTP header for the last request sent the user agent
1.58 avankest 980: <em class="ct">must</em> return the value of that header and abort these
1.76 avankest 981: steps.</p></li>
1.58 avankest 982:
1.76 avankest 983: <li><p>The method <em class="ct">must</em> return
984: <code>null</code>.</p></li>
1.58 avankest 985: </ol>
1.12 avankest 986:
1.1 avankest 987: <div class="example">
1.58 avankest 988: <pre><code>// The following script:
1.1 avankest 989: var client = new XMLHttpRequest();
1.14 avankest 990: client.open("GET", "test.txt", true);
1.5 avankest 991: client.send();
1.12 avankest 992: client.onreadystatechange = function() {
1.13 avankest 993: if(this.readyState == 3) {
1.14 avankest 994: print(client.getResponseHeader("Content-Type"));
1.12 avankest 995: }
996: }
1.1 avankest 997:
1.5 avankest 998: // ...should output something similar to the following text:
1.58 avankest 999: Content-Type: text/plain; charset=utf-8</code></pre>
1.1 avankest 1000: </div>
1.5 avankest 1001: </dd>
1.12 avankest 1002:
1.5 avankest 1003: <dt><dfn id="dfn-responsetext"><code>responseText</code></dfn> of type
1.22 avankest 1004: <code>DOMString</code>, readonly</dt>
1.12 avankest 1005:
1.5 avankest 1006: <dd>
1.63 avankest 1007: <p>If the state is not <span title="RECEIVING state">RECEIVING</span> or
1.79 avankest 1008: <span title="DONE state">DONE</span>, the user agent
1.40 avankest 1009: <em class="ct">must</em> raise an <code>INVALID_STATE_ERR</code>
1010: exception. Otherwise, if there's no <span>entity body</span> this
1011: attribute <em class="ct">must</em> be <code>null</code>. If there is, it
1012: <em class="ct">must</em> be the fragment of the <span>entity body</span>
1013: received so far (when the state is
1.63 avankest 1014: <span title="RECEIVING state">RECEIVING</span>) or the complete
1.40 avankest 1015: <span>entity body</span> (when the state is
1.79 avankest 1016: <span title="DONE state">DONE</span>), interpreted as a stream of
1.40 avankest 1017: characters.</p>
1.12 avankest 1018:
1.50 avankest 1019: <p>If the response includes a MIME type understood by the user agent the
1020: characters <em class="ct">must</em> be decoded following the relevant MIME
1021: type specification. If the user agent cannot derive a character stream in
1022: accord with the media type specification, <code>responseText</code>
1023: <em class="ct">must</em> be <code>null</code>.</p>
1.12 avankest 1024:
1.40 avankest 1025: <p>Its initial value <em class="ct">must</em> be the
1026: <code>null</code>.</p>
1.5 avankest 1027: </dd>
1.12 avankest 1028:
1.5 avankest 1029: <dt><dfn id="dfn-responsexml"><code>responseXML</code></dfn> of type
1.22 avankest 1030: <code>Document</code>, readonly</dt>
1.12 avankest 1031:
1.8 avankest 1032: <dd>
1.75 avankest 1033: <p>On getting, the user agent <em class="ct">must</em> run the following
1034: steps:</p>
1.79 avankest 1035:
1.75 avankest 1036: <ol>
1.79 avankest 1037: <li><p>If the state is not <span title="DONE state">DONE</span> the user
1038: agent <em class="ct">must</em> raise an <code>INVALID_STATE_ERR</code>
1039: exception and abort these steps.</p></li>
1.75 avankest 1040:
1041: <li><p>If there's no <span>entity body</span> the user agent
1042: <em class="ct">must</em> return <code>null</code> and abort these
1043: steps.</p></li>
1.79 avankest 1044:
1.75 avankest 1045: <li><p>If there is no <code>Content-Type</code> header the user agent
1046: <em class="ct">must</em> return <code>null</code> and abort these
1047: steps.</p></li>
1.79 avankest 1048:
1.75 avankest 1049: <li><p>If the <code>Content-Type</code> header does not contain a media
1050: type (ignoring any parameters) that is <code>text/xml</code>,
1051: <code>application/xml</code> or ends in <code title="">+xml</code> the
1052: user agent <em class="ct">must</em> return <code>null</code> and abort
1053: these steps.</p></li>
1.79 avankest 1054:
1.75 avankest 1055: <li><p>If the <span>entity body</span> can not be parsed into a namespace
1056: well-formed XML document the user agent <em class="ct">must</em> return
1.77 avankest 1057: <code>null</code> and abort these steps. [<cite><span>XML</span></cite>]
1058: [<cite><span>XMLNS</span></cite>]</p></li>
1.79 avankest 1059:
1.75 avankest 1060: <li><p>The user agent <em class="ct">must</em> return an object
1061: implementing the <code>Document</code> interface representing the parsed
1062: document.</p></li>
1063: </ol>
1.5 avankest 1064: </dd>
1.12 avankest 1065:
1.22 avankest 1066: <dt><dfn id="dfn-status"><code>status</code></dfn> of type <code>unsigned
1067: short</code>, readonly</dt>
1.12 avankest 1068:
1.5 avankest 1069: <dd>
1.72 avankest 1070: <p>On getting, if available, it <em class="ct">must</em> return the HTTP
1071: status code sent by the server (typically <code>200</code> for a
1072: successful request). Otherwise, if not available, the user agent
1073: <em class="ct">must</em> raise an <code>INVALID_STATE_ERR</code>
1074: exception.</p>
1.12 avankest 1075: </dd>
1076:
1.5 avankest 1077: <dt><dfn id="dfn-statustext"><code>statusText</code></dfn> of type
1.22 avankest 1078: <code>DOMString</code>, readonly</dt>
1.12 avankest 1079:
1.5 avankest 1080: <dd>
1.72 avankest 1081: <p>On getting, if available, it <em class="ct">must</em> return the HTTP
1082: status text sent by the server (appears after the status code). Otherwise,
1083: if not available, the user agent <em class="ct">must</em> raise an
1084: <code>INVALID_STATE_ERR</code> exception.</p>
1.1 avankest 1085: </dd>
1086: </dl>
1.12 avankest 1087:
1.31 avankest 1088: <h3 id="events">Events for the <code title="">XMLHttpRequest</code>
1089: Object</h3>
1.12 avankest 1090:
1.1 avankest 1091: <p>These sections describe the various events that can be dispatched on the
1.22 avankest 1092: object implementing the <code>XMLHttpRequest</code> interface. For this
1093: version of the specification only one event is defined.</p>
1.12 avankest 1094:
1.1 avankest 1095: <dl>
1096: <dt><dfn id="dfn-readystatechange"><code>readystatechange</code></dfn></dt>
1.24 avankest 1097:
1.72 avankest 1098: <dd>When the user agent dispatches a <code title="">readystatechange</code>
1099: event (as indicated above) it <em class="ct">must not</em> bubble,
1100: <em class="ct">must not</em> be cancelable and <em class="ct">must</em>
1101: implement the <code>Event</code> interface. Its <code>namespaceURI</code>
1102: attribute <em class="ct">must</em> be <code>null</code>.
1103: [<cite><span>DOM3Events</span></cite>]</dd>
1.1 avankest 1104: </dl>
1.32 avankest 1105:
1.31 avankest 1106: <h3 id="exceptions">Exceptions for the <code title="">XMLHttpRequest</code>
1107: Object</h3>
1108:
1.32 avankest 1109: <pre class="idl">exception <dfn>XMLHttpRequestException</dfn> {
1.31 avankest 1110: unsigned short code;
1111: };
1112: const unsigned short <span>NETWORK_ERR</span> = 101;</pre>
1113:
1.33 avankest 1114: <p>The <dfn id="network-err"><code>NETWORK_ERR</code></dfn> exception is
1115: thrown when a network error occurs in synchronous requests. See the section
1116: on <code>send()</code> for more details.</p>
1.11 avankest 1117:
1.29 avankest 1118: <h2 class="no-num" id="notcovered">Not in this Specification</h2>
1119:
1120: <p><em>This section is non normative.</em></p>
1121:
1.72 avankest 1122: <p>This specification does not include the following features which are
1123: being considered for a future version of this specification:</p>
1.29 avankest 1124:
1125: <ul>
1126: <li><code>load</code> event and <code>onload</code> attribute;</li>
1127: <li><code>error</code> event and <code>onerror</code> attribute;</li>
1128: <li><code>progress</code> event and <code>onprogress</code> attribute;</li>
1129: <li><code title="">abort</code> event and <code>onabort</code> attribute;</li>
1130: <li>Timers have been suggested, perhaps an <code>ontimeout</code>
1131: attribute;</li>
1132: <li>Property to disable following redirects;</li>
1.30 avankest 1133: <li><code title="">responseXML</code> for <code>text/html</code>
1134: documents;</li>
1.40 avankest 1135: <li>Cross-site <code title="">XMLHttpRequest</code>;</li>
1136: <li>Deal with byte streams;</li>
1137: <li><code>getRequestHeader</code> and
1138: <code>removeRequestHeader</code>.</li>
1.29 avankest 1139: </ul>
1140:
1.1 avankest 1141: <h2 class="no-num" id="bibref">References</h2>
1.11 avankest 1142:
1.6 avankest 1143: <dl>
1.37 avankest 1144: <dt>[<dfn id="DOM3">DOM3Core</dfn>]</dt>
1.24 avankest 1145:
1.11 avankest 1146: <dd><cite><a href="http://www.w3.org/TR/DOM-Level-3-Core">Document Object
1147: Model (DOM) Level 3 Core Specification</a></cite>, A. Le Hors, P. Le
1148: Hégaret, L. Wood, G. Nicol, J. Robie, M. Champion, S. Byrne, editors.
1149: World Wide Web Consortium, April 2004.</dd>
1150:
1.37 avankest 1151: <dt>[<dfn id="DOM3EV">DOM3Events</dfn>]</dt>
1.24 avankest 1152:
1.1 avankest 1153: <dd><cite><a href="http://www.w3.org/TR/DOM-Level-3-Events/">Document Object
1.11 avankest 1154: Model (DOM) Level 3 Events Specification</a></cite>, Björn Höhrmann, editor.
1155: World Wide Web Consortium, April 2006.</dd>
1156:
1.37 avankest 1157: <dt>[<dfn id="ref-ecmascript">ECMAScript</dfn>]</dt>
1.24 avankest 1158:
1.14 avankest 1159: <dd><cite><a href="http://www.ecma-international.org/publications/standards/Ecma-262.htm">ECMAScript
1160: Language Specification</a></cite>, Third Edition. ECMA, December 1999.</dd>
1161:
1.37 avankest 1162: <dt>[<dfn id="ref-rfc2046">RFC2046</dfn>]</dt>
1.24 avankest 1163:
1.19 avankest 1164: <dd><cite><a href="http://ietf.org/rfc/rfc2046">Multipurpose Internet Mail
1165: Extensions (MIME) Part Two: Media Types</a></cite>, N. Freed, N. Borenstein,
1166: editors. IETF, November 1996.</dd>
1.14 avankest 1167:
1.37 avankest 1168: <dt>[<dfn id="RFC2119">RFC2119</dfn>]</dt>
1.24 avankest 1169:
1.11 avankest 1170: <dd><cite><a href="http://ietf.org/rfc/rfc2119">RFC 2119: Key words
1171: for use in RFCs to Indicate Requirement Levels</a></cite>, S. Bradner.
1172: IETF, March 1997.</dd>
1.12 avankest 1173:
1.37 avankest 1174: <dt>[<dfn id="RFC2616">RFC2616</dfn>]</dt>
1.24 avankest 1175:
1.11 avankest 1176: <dd><cite><a href="http://ietf.org/rfc/rfc2616">Hypertext Transfer Protocol
1177: -- HTTP/1.1</a></cite>, R. Fielding, J. Gettys, J. Mogul, H. Frystyk, L.
1178: Masinter, P. Leach, T. Berners-Lee, editors. IETF, June 1999</dd>
1.12 avankest 1179:
1.37 avankest 1180: <dt>[<dfn id="ref-rfc2617">RFC2617</dfn>]</dt>
1.24 avankest 1181:
1.11 avankest 1182: <dd><cite><a href="http://ietf.org/rfc/rfc2617">HTTP Authentication: Basic
1.14 avankest 1183: and Digest Access Authentication</a></cite>, ...</dd>
1.12 avankest 1184:
1.37 avankest 1185: <dt>[<dfn id="ref-rfc2965">RFC2965</dfn>]</dt>
1.24 avankest 1186:
1.19 avankest 1187: <dd><cite><a href="http://ietf.org/rfc/rfc2965">HTTP State Management
1188: Mechanism</a></cite>, D. Kristol, L. Montulli, editors. IETF, October
1189: 2000.</dd>
1190:
1.37 avankest 1191: <dt>[<dfn id="ref-rfc3986">RFC3986</dfn>]</dt>
1.24 avankest 1192:
1.11 avankest 1193: <dd><cite><a href="http://ietf.org/rfc/rfc3986">Uniform Resource Identifier
1194: (URI): Generic Syntax</a></cite>, T. Berners-Lee, R. Fielding, L. Masinter,
1195: editors. IETF, January 2005.</dd>
1.28 avankest 1196:
1.37 avankest 1197: <dt>[<dfn id="ref-window">Window</dfn>]</dt>
1.28 avankest 1198:
1199: <dd><cite><a href="http://www.w3.org/TR/Window/">Window Object
1200: 1.0</a></cite>, I. Davis, M. Stachowiak, editors. W3C, April 2006.</dd>
1.41 avankest 1201:
1202: <dt>[<dfn id="ref-xml">XML</dfn>]</dt>
1203:
1204: <dd><cite><a href="http://www.w3.org/TR/xml/">Extensible
1205: Markup Language (XML) 1.0 (Fourth Edition)</a></cite>, T. Bray, J. Paoli,
1206: C. Sperberg-McQueen, E. Maler, F. Yergeau. W3C, September 2006.</dd>
1207:
1208: <dt>[<dfn id="ref-xmlns">XMLNS</dfn>]</dt>
1209:
1210: <dd><cite><a href="http://www.w3.org/TR/xml-names/">Namespaces in
1211: XML (Second Edition)</a></cite>, T. Bray, D. Hollander, A. Layman, R.
1212: Tobin. W3C, August 2006.</dd>
1.1 avankest 1213: </dl>
1.11 avankest 1214:
1.1 avankest 1215: <h2 class="no-num" id="acknowledgements">Acknowledgements</h2>
1.11 avankest 1216:
1.1 avankest 1217: <p><em>This section is non-normative</em></p>
1.12 avankest 1218:
1.7 avankest 1219: <p>The editor would like to thank to the following people who have contributed
1.33 avankest 1220: to this specification (ordered by first name):</p>
1.12 avankest 1221:
1.1 avankest 1222: <ul>
1.22 avankest 1223: <li>Alex Hopmann</li>
1.7 avankest 1224: <li>Alex Vincent</li>
1.15 avankest 1225: <li>Alexey Proskuryakov</li>
1.1 avankest 1226: <li>Asbjørn Ulsberg</li>
1227: <li>Boris Zbarsky</li>
1228: <li>Björn Höhrmann</li>
1229: <li>Cameron McCormack</li>
1230: <li>Christophe Jolif</li>
1231: <li>Charles McCathieNevile</li>
1.54 avankest 1232: <li>Dan Winship</li>
1.72 avankest 1233: <li>David Håsäther</li>
1.1 avankest 1234: <li>Dean Jackson</li>
1235: <li>Doug Schepers</li>
1236: <li>Douglas Livingstone</li>
1237: <li>Gorm Haug Eriksen</li>
1238: <li>Hallvord R. M. Steen</li>
1239: <li>Håkon Wium Lie</li>
1240: <li>Ian Davis</li>
1241: <li>Ian Hickson</li>
1242: <li>Ivan Herman</li>
1243: <li>Jens Lindström</li>
1244: <li>Jim Deegan</li>
1245: <li>Jim Ley</li>
1246: <li>Jonas Sicking</li>
1247: <li>Julian Reschke</li>
1248: <li>Karl Dubost</li>
1249: <li>Maciej Stachowiak</li>
1.7 avankest 1250: <li>Magnus Kristiansen</li>
1.1 avankest 1251: <li>Marc Hadley</li>
1.53 avankest 1252: <li>Marcos Caceres</li>
1.1 avankest 1253: <li>Mark Nottingham</li>
1254: <li>Pawel Glowacki</li>
1255: <li>Robin Berjon</li>
1256: <li>Ruud Steltenpool</li>
1.33 avankest 1257: <li>Simon Pieters</li>
1.1 avankest 1258: </ul>
1.12 avankest 1259:
1.1 avankest 1260: <p>Special thanks to the Microsoft employees who first implemented the
1.22 avankest 1261: <code>XMLHttpRequest</code> interface, which was first widely deployed by the
1262: Windows Internet Explorer browser.</p>
1.12 avankest 1263:
1.54 avankest 1264: <p>Special thanks also to the WHATWG for drafting an initial version of this
1.22 avankest 1265: specification in their Web Applications 1.0 document.</p>
1.12 avankest 1266:
1.1 avankest 1267: <p>Thanks also to all those who have helped to improve this specification by
1.22 avankest 1268: sending suggestions and corrections. (Please, keep bugging us with your
1269: issues!)</p>
1.1 avankest 1270: </body>
1271: </html>
Webmaster