[BACK] Return to Overview.src.html CVS log [TXT] [DIR] Up to [Public] / 2006 / webapi / XMLHttpRequest

Annotation of 2006/webapi/XMLHttpRequest/Overview.src.html, revision 1.176

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

Webmaster

AltStyle によって変換されたページ (->オリジナル) /