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

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

Webmaster

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