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

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

Webmaster

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