[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.201

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

Webmaster

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