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

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

Webmaster

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