diff --git a/xhr.bs b/xhr.bs index 4e5f430..b96846a 100644 --- a/xhr.bs +++ b/xhr.bs @@ -14,15 +14,6 @@ urlPrefix: https://w3c.github.io/DOM-Parsing/; spec: dom-parsing type: dfn; text: fragment serializing algorithm; url: dfn-fragment-serializing-algorithm -
-{ - "HTTP": { - "aliasOf": "HTTP11" - }, - "XMLNS": { - "aliasOf": "XML-NAMES" - } -}
The {{XMLHttpRequest}} object was initially defined as part of the WHATWG's HTML effort. (Based on Microsoft's implementation many years prior.) -It moved to the W3C in 2006. Extensions (e.g. progress events and +It moved to the W3C in 2006. Extensions (e.g., progress events and cross-origin requests) to {{XMLHttpRequest}} were developed in a separate draft (XMLHttpRequest Level 2) until end of 2011, at which point the two drafts were merged and {{XMLHttpRequest}} became a single @@ -106,32 +97,13 @@ archives: -
All diagrams, examples, and notes in this specification are -non-normative, as are all sections explicitly marked non-normative. -Everything else in this specification is normative. - -
The key words "MUST", "MUST NOT", "REQUIRED", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and -"OPTIONAL" in the normative parts of this specification are to be -interpreted as described in RFC2119. For readability, these words do -not appear in all uppercase letters in this specification. -[[!RFC2119]] - - -
User agents, Working Groups, and other interested parties are -strongly encouraged to discuss new features with the WHATWG -community. -
This specification uses terminology, cross-linked throughout, from DOM, -DOM Parsing and Serialization, Encoding, Feature Policy, Fetch, File API, HTML, -HTTP, URL, Web IDL, and XML. +
This specification depends on the Infra Standard. [[!INFRA]] + +
This specification uses terminology from DOM, DOM Parsing and Serialization, Encoding, +Feature Policy, Fetch, File API, HTML, URL, Web IDL, and XML. [[!DOM]] [[!DOM-PARSING]] @@ -140,12 +112,11 @@ HTTP, URL, Web IDL, and XML. [[!FETCH]] [[!FILEAPI]] [[!HTML]] -[[!HTTP]] [[!URL]] [[!WEBIDL]] -[[!XML]] [[!XMLNS]] +[[!XML]] [[!XML-NAMES]] + -
It uses the typographic conventions from HTML. [[!HTML]]
An {{XMLHttpRequest}} object has an associated -{{XMLHttpRequestUpload}} object. +
An {{XMLHttpRequest}} object has an associated: + +
send()
flag
+ An {{XMLHttpRequest}} object has an associated -state, which is one of -unsent, -opened, -headers received, -loading, and -done. Unless stated otherwise it is unsent. +
An {{XMLHttpRequest}} object has an associated
-send()
flag. Unless stated otherwise it is unset.
+
arraybuffer
", "blob
",
+ "document
", "json
", and "text
"; initially the empty string.
+
+ The XMLHttpRequest()
-constructor, when invoked, must return a new {{XMLHttpRequest}} object.
+
The
+new XMLHttpRequest()
+constructor steps are:
+
+
Set this's upload object to a new
+ XMLHttpRequestUpload
object.
+
The
-readyState
-attribute's getter must return the value from the table below in the cell of the second column, from
-the row where the value in the cell in the first column is context object's state:
+
The readyState
getter steps are to return
+the value from the table below in the cell of the second column, from the row where the value in the
+cell in the first column is this's state:
opened | OPENED (numeric value 1)
| The open() method has
- been successfully invoked. During this state request headers can be set using
- setRequestHeader() and the fetch can be initiated using the
- send() method.
+ been successfully invoked. During this state request headers can be set using
+ setRequestHeader() and the fetch can be initiated using the
+ send() method.
| ||
headers received - | HEADERS_RECEIVED
- (numeric value 2)
- | All redirects (if any) have been followed and all HTTP headers of the - response have been received. + | HEADERS_RECEIVED (numeric value 2)
+ | All redirects (if any) have been followed and all headers of a response have been received. |
loading | LOADING (numeric value 3)
- | The response's - body is being received. + | The response body is being received. | |
done | DONE (numeric value 4)
- | The data transfer has been completed or something went wrong during the transfer - (e.g. infinite redirects). + | The data transfer has been completed or something went wrong during the transfer (e.g., + infinite redirects). |
Each {{XMLHttpRequest}} object has the following request-associated concepts: -request method, -request URL, -author request headers, -request body, -synchronous flag, -upload complete flag, -upload listener flag, and -timed out flag. - -
The author request headers is an initially empty -header list. - -
The request body is initially null. - -
The synchronous flag, upload complete flag, upload listener flag and -timed out flag are initially unset. -
Registering one or more event listeners on an {{XMLHttpRequestUpload}} object will result in a CORS-preflight request. (That is because registering an event listener causes the upload listener flag to be set, which in @@ -399,7 +401,7 @@ turn causes the use-CORS-preflight flag to be set.) synchronous flag.
Throws a "{{SyntaxError!!exception}}" {{DOMException}} if either method is not a - valid HTTP method or url cannot be parsed. + valid method or url cannot be parsed.
Throws a "{{SecurityError!!exception}}" {{DOMException}} if method is a
case-insensitive match for `CONNECT
`, `TRACE
`, or `TRACK
`.
@@ -420,10 +422,10 @@ agents are strongly encouraged to warn about such usage in developer tools and m
open(method, url)
and
open(method, url, async, username, password)
-methods, when invoked, must run these steps:
+method steps are:
Let settingsObject be context object's relevant settings object. +
Let settingsObject be this's relevant settings object.
If settingsObject has a responsible document and it is not fully active, then throw an "{{InvalidStateError!!exception}}" {{DOMException}}. @@ -463,10 +465,9 @@ methods, when invoked, must run these steps: password.
If async is false, current global object is a {{Window}} object, and the - {{XMLHttpRequest/timeout!!attribute}} attribute value is not zero or the - {{XMLHttpRequest/responseType}} attribute value is not the empty string, then throw an - "{{InvalidAccessError!!exception}}" {{DOMException}}. +
If async is false, the current global object is a {{Window}} object, and + either this's timeout is not 0 or this's response type is not + the empty string, then throw an "{{InvalidAccessError!!exception}}" {{DOMException}}.
Terminate the ongoing fetch operated by the @@ -479,29 +480,28 @@ methods, when invoked, must run these steps:
Set variables associated with the object as follows:
Unset the send()
flag and upload listener flag.
-
Set request method to method. -
Set request URL to parsedURL. -
Set the synchronous flag, if async is false, and unset - the synchronous flag otherwise. -
Empty author request headers. -
Set response to a - network error. -
Set received bytes to the empty byte sequence. -
Set response object to null. +
Unset this's send()
flag.
+
Unset this's upload listener flag. +
Set this's request method to method. +
Set this's request URL to parsedURL. +
Set this's synchronous flag if async is false; otherwise unset + this's synchronous flag. +
Set this's response to a network error. +
Set this's received bytes to the empty byte sequence. +
Set this's response object to null.
Override MIME type is not overridden here as the
overrideMimeType()
method can be invoked before the open()
method.
If the state is not opened, then: +
If this's state is not opened, then:
Set state to - opened. +
Fire an event named readystatechange
at this.
+
Fire an event named readystatechange
at this.
If this's state is not opened, then throw an "{{InvalidStateError!!exception}}" {{DOMException}}. -
If the send()
flag is set, then throw an
+
If this's send()
flag is set, then throw an
"{{InvalidStateError!!exception}}" {{DOMException}}.
Normalize value. @@ -545,10 +545,9 @@ method must run these steps:
Terminate these steps if name is a - forbidden header name. +
If name is a forbidden header name, then return. -
Combine name/value in +
Combine name/value in this's author request headers.
timeout
attributetimeout
getter and setterclient . timeout
Can be set to a time in milliseconds. When set to a non-zero value will cause
fetching to terminate after the given time has passed. When the time has passed, the
- request has not yet completed, and the synchronous flag is unset, a
+ request has not yet completed, and this's synchronous flag is unset, a
timeout
event will then be dispatched, or a
"{{TimeoutError!!exception}}" {{DOMException}} will be thrown otherwise (for the
send()
method).
@@ -585,17 +584,17 @@ client.send();
synchronous flag is set and current global object is a {{Window}} object.
The timeout
-attribute must return its value. Initially its value must be zero.
+
The timeout
getter steps are to return
+this's timeout.
-
Setting the {{XMLHttpRequest/timeout!!attribute}} -attribute must run these steps: +
The {{XMLHttpRequest/timeout!!attribute}} setter steps are:
If current global object is a {{Window}} object and the synchronous flag is - set, then throw an "{{InvalidAccessError!!exception}}" {{DOMException}}. +
If the current global object is a {{Window}} object and this's + synchronous flag is set, then throw an "{{InvalidAccessError!!exception}}" + {{DOMException}}. -
Set its value to the new value. +
This implies that the @@ -605,7 +604,7 @@ progress. If that occurs it will still be measured relative to the start of fetching. -
withCredentials
attributewithCredentials
getter and setterclient . withCredentials
@@ -618,32 +617,23 @@ of fetching.
unsent or opened, or if the send()
flag is set.
The
-withCredentials
-attribute must return its value. Initially its value must be false.
+
The withCredentials
getter steps are to
+return this's cross-origin credentials.
-
Setting the -{{XMLHttpRequest/withCredentials}} -attribute must run these steps: +
The {{XMLHttpRequest/withCredentials}} setter steps are:
If this's state is not unsent or opened, then throw an "{{InvalidStateError!!exception}}" {{DOMException}}. -
If the send()
flag is set, then throw an
+
If this's send()
flag is set, then throw an
"{{InvalidStateError!!exception}}" {{DOMException}}.
-
Set the {{XMLHttpRequest/withCredentials}} - attribute's value to the given value. +
Set this's cross-origin credentials to the given value.
The {{XMLHttpRequest/withCredentials}} -attribute has no effect when -fetching -same-origin resources. - -
upload
attributeupload
getterclient . upload
@@ -652,13 +642,8 @@ attribute has no effect when
transferred to a server.
The
-upload
-attribute must return the associated
-{{XMLHttpRequestUpload}} object.
-
-
As indicated earlier, each {{XMLHttpRequest}} -object has an associated {{XMLHttpRequestUpload}} object. +
The upload
getter steps are to return
+this's upload object.
send()
methodsend()
flag is set.
-The send(body)
-method must run these steps:
+
The send(body)
method steps are:
If this's state is not opened, then throw an "{{InvalidStateError!!exception}}" {{DOMException}}. -
If the send()
flag is set, then throw an
+
If this's send()
flag is set, then throw an
"{{InvalidStateError!!exception}}" {{DOMException}}.
-
If the request method is GET
or
- HEAD
, set body to null.
+
If this's request method is `GET
` or `HEAD
`, then
+ set body to null.
If body is not null, then: @@ -692,27 +676,24 @@ method must run these steps:
Let extractedContentType be null. -
If body is a {{Document}}, then set request body to +
If body is a {{Document}}, then set this's request body to body, serialized, converted, and UTF-8 encoded. -
Otherwise, set request body and extractedContentType to the result of - extracting body. +
Otherwise, set this's request body and extractedContentType to + the result of safely extracting body. + +
Let originalAuthorContentType be the result of getting
+ `Content-Type
` from this's author request headers.
If author request headers contains
- `Content-Type
`, then:
+
If originalAuthorContentType is non-null, then:
If body is a {{Document}} or a {{USVString}}, then:
Let originalAuthorContentType be the value of the
- header whose name is a byte-case-insensitive match for
- `Content-Type
` in author request headers.
-
-
Let contentTypeRecord be the result of parsing originalAuthorContentType. @@ -730,30 +711,32 @@ method must run these steps: serializing contentTypeRecord.
Set
- `Content-Type
`/newContentTypeSerialized in
+ `Content-Type
`/newContentTypeSerialized in this's
author request headers.
Otherwise:
If body is an HTML document, set
- `Content-Type
`/`text/html;charset=UTF-8
` in
+ `Content-Type
`/`text/html;charset=UTF-8
` in this's
author request headers.
Otherwise, if body is an XML document, set
- `Content-Type
`/`application/xml;charset=UTF-8
` in
+ `Content-Type
`/`application/xml;charset=UTF-8
` in this's
author request headers.
Otherwise, if extractedContentType is not null, set
- `Content-Type
`/extractedContentType in author request headers.
+ `Content-Type
`/extractedContentType in this's
+ author request headers.
If one or more event listeners are registered on the associated - {{XMLHttpRequestUpload}} object, then set upload listener flag. +
If one or more event listeners are registered on this's upload object, then + set this's upload listener flag.
Let req be a new @@ -762,60 +745,53 @@ method must run these steps:
cors
"
+ cors
".
include
", and "same-origin
"
- otherwise.
+ include
";
+ otherwise "same-origin
".
Unset the upload complete flag. +
Unset this's upload complete flag. -
Unset the timed out flag. +
Unset this's timed out flag. -
If req's - body is null, - set the upload complete flag. +
If req's body is null, then set this's + upload complete flag. -
Set the send()
flag.
+
Set this's send()
flag.
If the synchronous flag is unset, then: +
If this's synchronous flag is unset, then:
Fire a progress event named loadstart
at this with 0 and 0.
+
Fire a progress event named loadstart
at this
+ with 0 and 0.
-
If the upload complete flag is unset and upload listener flag is
- set, then fire a progress event named
- loadstart
at this's
- {{XMLHttpRequestUpload}} object with 0 and req's
- body's
- total bytes.
+
If this's upload complete flag is unset and this's
+ upload listener flag is set, then fire a progress event named
+ loadstart
at this's upload object with 0 and
+ req's body's total bytes.
-
If state is not opened or the send()
flag is unset, then
- return.
+
If this's state is not opened or this's
+ send()
flag is unset, then return.
Fetch req. @@ -826,16 +802,11 @@ method must run these steps:
Run these steps in parallel:
Wait until either req's done flag is set or - -
the {{XMLHttpRequest/timeout!!attribute}} attribute value number of milliseconds has - passed since these steps started -
while {{XMLHttpRequest/timeout!!attribute}} attribute value is not zero. -
Wait until either req's done flag is set or this's + timeout is not 0 and this's timeout milliseconds have passed since these + steps started. -
If req's done flag is unset, then set the +
If req's done flag is unset, then set this's timed out flag and terminate fetching.
If not roughly 50ms have passed since these steps were last invoked, terminate these steps. -
If upload listener flag is set, then
- fire a progress event named
- progress
at this's
- {{XMLHttpRequestUpload}} object with request's
- body's
- transmitted bytes and
- request's
- body's
- total bytes.
+
If this's upload listener flag is set, then fire a progress event
+ named progress
at this's upload object with
+ request's body's transmitted bytes and
+ request's body's total bytes.
To process request end-of-body for request, run these steps:
Set the upload complete flag. +
Set this's upload complete flag. -
If upload listener flag is unset, then terminate these steps. +
If this's upload listener flag is unset, then terminate these steps.
Let transmitted be request's body's @@ -874,50 +840,41 @@ method must run these steps: body's total bytes. -
Fire a progress event named
- progress
at this's
- {{XMLHttpRequestUpload}} object with transmitted and
- length.
+
Fire a progress event named progress
at this's
+ upload object with transmitted and length.
-
Fire a progress event named
- load
at this's
- {{XMLHttpRequestUpload}} object with transmitted and
- length.
+
Fire a progress event named load
at this's
+ upload object with transmitted and length.
-
Fire a progress event named
- loadend
at this's
- {{XMLHttpRequestUpload}} object with transmitted and
- length.
+
Fire a progress event named loadend
at this's
+ upload object with transmitted and length.
To process response for response, run these steps:
Set response to response. +
Handle errors for response. +
Handle errors fo this and response. -
If response is a - network error, +
If this's response is a network error, then return. -
Set state to - headers received. +
Fire an event named
- readystatechange
at this.
+
Fire an event named readystatechange
at this.
-
If state is not - headers received, then return. +
If response's - body is null, - then run handle response end-of-body and return. +
If this's response's body is null, + then run handle response end-of-body for this and this's + response, and then return.
Let reader be the result of getting a reader for - response's body's stream. + this's response's body's + stream.
This operation will not throw an exception. @@ -928,35 +885,36 @@ method must run these steps:
Append chunk to received bytes. +
Append chunk to this's received bytes.
If not roughly 50ms have passed since these steps were last invoked, then abort these steps. -
If this's state is headers received, then set this's + state to loading.
Fire an event named readystatechange
at this.
+
Fire an event named readystatechange
at this.
Web compatibility is the reason
- readystatechange
fires more often than state changes.
+ readystatechange
fires more often than this's
+ state changes.
-
Fire a progress event named progress
at this
- with response's body's transmitted bytes and
- response's body's total bytes.
+
Fire a progress event named progress
at this
+ with this's response's body's
+ transmitted bytes and this's response's
+ body's total bytes.
Run handle response end-of-body for response. -
Run handle response end-of-body for this and this's + response.
Run handle errors for response. -
Run handle errors for this and this's + response.
Read a chunk from reader given @@ -965,25 +923,23 @@ method must run these steps:
Otherwise, if the synchronous flag is set, run these steps: +
Otherwise, if this's synchronous flag is set:
If context object's relevant settings object has a
- responsible document which is not allowed to use the
- "sync-xhr
" feature, then run handle response end-of-body for a
- network error and return.
+
If this's relevant settings object has a responsible document which
+ is not allowed to use the "sync-xhr
" feature, then run
+ handle response end-of-body for this and a network error, and then return.
Let response be the result of fetching req. -
If the {{XMLHttpRequest/timeout!!attribute}} attribute value is not zero, then set the - timed out flag and terminate fetching if it has not - returned within the amount of milliseconds from the {{XMLHttpRequest/timeout!!attribute}}. +
If this's timeout is not 0, then set this's timed out flag and + terminate fetching if it has not returned within this's + timeout milliseconds. -
If response's - body is null, - then run handle response end-of-body and return. +
If response's body is null, then run + handle response end-of-body for this and response, and then return.
Let reader be the result of getting a reader for @@ -997,27 +953,27 @@ method must run these steps:
Wait for promise to be fulfilled or rejected.
If promise is fulfilled with bytes, then append bytes - to received bytes. + to this's received bytes. -
Run handle response end-of-body for response. +
Run handle response end-of-body for this and response.
To handle response end-of-body for -response, run these steps: +
To handle response end-of-body for an +{{XMLHttpRequest}} object xhr and a response response, run these +steps:
If the synchronous flag is set, set response to - response. +
If xhr's synchronous flag is set, then set xhr's + response to response. -
Handle errors for response. +
Handle errors for xhr and response. -
If response is a - network error, return. +
If xhr's response is a network error, then + return. -
If the synchronous flag is unset, update response's - body using - response. +
If xhr's synchronous flag is unset, then update xhr's + response's body using response.
Let transmitted be response's body's transmitted bytes. @@ -1025,34 +981,35 @@ method must run these steps:
Let length be response's body's total bytes. -
If the synchronous flag is unset, fire a progress event named
- progress
at this with transmitted and length.
+
If xhr's synchronous flag is unset, then fire a progress event
+ named progress
at xhr with transmitted and
+ length.
-
Set state to done. +
Set xhr's state to done. -
Unset the send()
flag.
+
Unset xhr's send()
flag.
-
Fire an event named readystatechange
at this.
+
Fire an event named readystatechange
at xhr.
-
Fire a progress event named load
- at this
- with transmitted and length.
+
Fire a progress event named load
at xhr with
+ transmitted and length.
-
Fire a progress event named loadend
- at this
- with transmitted and length.
+
Fire a progress event named loadend
at xhr with
+ transmitted and length.
To handle errors for response run these steps: +
To handle errors for an {{XMLHttpRequest}} object xhr and a +response response, run these steps:
If the send()
flag is unset, return.
+
If xhr's send()
flag is unset, then return.
-
If the timed out flag is set, then run the request error steps for event
- timeout
and exception "{{TimeoutError!!exception}}" {{DOMException}}.
+
If xhr's timed out flag is set, then run the request error steps
+ for xhr, timeout
, and "{{TimeoutError!!exception}}"
+ {{DOMException}}.
If response is a network error, then run the request error steps
- for event error
and exception "{{NetworkError!!exception}}"
+ for xhr, error
, and "{{NetworkError!!exception}}"
{{DOMException}}.
Set state to done. +
Set xhr's state to done. -
Unset the send()
flag.
+
Unset xhr's send()
flag.
-
Set response to a network error. +
Set xhr's response to a network error.
Otherwise, if response's aborted flag is set, then run the
- request error steps for event abort
and exception
- "{{AbortError!!exception}}" {{DOMException}}.
+
Otherwise, if xhr's response's aborted flag is
+ set, then run the request error steps for xhr, abort
,
+ and "{{AbortError!!exception}}" {{DOMException}}.
The request error steps for event event and optionally an -exception exception are: +
The request error steps for an {{XMLHttpRequest}} object xhr, +event, and optionally exception are:
Set state to done. +
Set xhr's state to done. -
Unset the send()
flag.
+
Unset xhr's send()
flag.
-
Set response to a - network error. +
Set xhr's response to a network error. -
If the synchronous flag is set, - throw an exception - exception. +
If xhr's synchronous flag is set, then throw exception.
Fire an event named readystatechange
at this.
+
Fire an event named readystatechange
at xhr.
-
At this point it is clear that the synchronous flag is unset. +
At this point it is clear that xhr's synchronous flag is unset.
If the upload complete flag is unset, then: +
If xhr's upload complete flag is unset, then:
Set the upload complete flag. +
Set xhr's upload complete flag.
If the upload listener flag is set, then: +
If xhr's upload listener flag is set, then:
Fire a progress event named event at this's {{XMLHttpRequestUpload}} - object with 0 and 0. +
Fire a progress event named event at xhr's + upload object with 0 and 0. -
Fire a progress event named loadend
at this's
- {{XMLHttpRequestUpload}} object with 0 and 0.
+
Fire a progress event named loadend
at xhr's
+ upload object with 0 and 0.
Fire a progress event named - event at this with 0 and 0. +
Fire a progress event named event at xhr with 0 and 0. -
Fire a progress event named
- loadend
at this with 0 and 0.
+
Fire a progress event named loadend
at xhr
+ with 0 and 0.
The abort()
method,
-when invoked, must run these steps:
+
The abort()
method steps are:
Terminate the ongoing fetch with the aborted flag set. -
If state is either
- opened with the send()
flag set,
- headers received, or loading, run the
- request error steps for event abort
.
+
If this's state is opened with this's
+ send()
flag set, headers received, or loading, then run the
+ request error steps for this and abort
.
If state is done, then set state to unsent and response to a - network error. +
If this's state is done, then set this's state to + unsent and this's response to a network error. -
No readystatechange
event
- is dispatched.
+
No readystatechange
event is dispatched.
An {{XMLHttpRequest}} has an associated response. Unless stated -otherwise it is a -network error. - -
An {{XMLHttpRequest}} also has an associated received bytes (a byte -sequence). Unless stated otherwise it is the empty byte sequence. +
responseURL
getterThe responseURL
getter steps are to return
+the empty string if this's response's URL is
+null; otherwise its serialization with the exclude fragment flag
+set.
-
responseURL
attributeThe responseURL
attribute
-must return the empty string if response's
-url is null and its
-serialization with the
-exclude fragment flag set otherwise.
+
status
getterThe status
getter steps are to return
+this's response's status.
-
status
attributeThe
-status
-attribute must return the response's
-status.
+
statusText
getterstatusText
attributeThe
-statusText
-attribute must return the response's
-status message.
+
The statusText
getter steps are to return
+this's response's status message.
getResponseHeader()
methodThe getResponseHeader(name)
method,
-when invoked, must return the result of getting name from
-response's header list
+
The getResponseHeader(name)
method
+steps are to return the result of getting name from
+this's response's header list.
-
The Fetch Standard filters response's -header list. [[!FETCH]] +
The Fetch Standard filters this's +response's header list. [[!FETCH]]
For the following script: @@ -1222,15 +1159,13 @@ text/plain; charset=UTF-8
Return A is byte less than B. -
The
-getAllResponseHeaders()
-method, when invoked, must run these steps:
+
The getAllResponseHeaders()
method steps are:
Let output be an empty byte sequence.
Let initialHeaders be the result of running sort and combine with - response's header list. + this's response's header list.
Let headers be the result of sorting initialHeaders in @@ -1247,9 +1182,8 @@ method, when invoked, must run these steps:
Return output.
The Fetch Standard filters response's -header list. -[[!FETCH]] +
The Fetch Standard filters this's +response's header list. [[!FETCH]]
For the following script: @@ -1279,32 +1213,44 @@ transfer-encoding: chunked
The response MIME type is the result of running these steps: +
To get a response MIME type for an {{XMLHttpRequest}} object +xhr, run these steps:
Let mimeType be the result of extracting a MIME type - from response's header list. + from xhr's response's header list.
If mimeType is failure, then set mimeType to text/xml
.
Return mimeType.
The override MIME type is initially null and can get a value -when {{overrideMimeType()}} is invoked. The final MIME type is the -override MIME type unless that is null in which case it is the response MIME type. +
To get a final MIME type for an {{XMLHttpRequest}} object +xhr, run these steps: + +
If xhr's override MIME type is null, return the result of + get a response MIME type for xhr. + +
Return xhr's override MIME type. +
The final charset is the return value of these steps: +
To get a final encoding for an {{XMLHttpRequest}} object +xhr, run these steps:
Let label be null. -
If response MIME type's parameters["charset
"]
- exists, then set label to it.
+
Let responseMIME be the result of get a response MIME type for + xhr. -
If override MIME type's parameters["charset
"]
+
If responseMIME's parameters["charset
"]
exists, then set label to it.
+
If xhr's override MIME type's
+ parameters["charset
"] exists, then set
+ label to it.
+
If label is null, then return null.
Let encoding be the result of getting an encoding from label.
@@ -1314,65 +1260,39 @@ when {{overrideMimeType()}} is invoked. The final MIME t
Return encoding.
The above steps intentionally do not use the final MIME type as it would yield -the wrong result. +
The above steps intentionally do not use the get a final MIME type as it would +not be web compatible.
An {{XMLHttpRequest}} object has an associated response object (an object, failure, -or null). Unless stated otherwise it is null. - - -
An arraybuffer response is the return value of these steps: - -
Set response object to a new {{ArrayBuffer}} object representing received bytes. - If this throws an exception, then set response object to failure and return null. - -
Allocating an {{ArrayBuffer}} object is not guaranteed to succeed. [[!ECMASCRIPT]] - -
Return response object. -
A blob response is the return value of these steps: +
To set a document response for an {{XMLHttpRequest}} object +xhr, run these steps:
Set response object to a new {{Blob}} object representing received bytes with - {{Blob/type}} set to the final MIME type. +
Return response object. -
A document response is the return value of these steps: - -
Let finalMIME be the result of get a final MIME type for xhr. -
If the final MIME type is not an HTML MIME type or an XML MIME type, - then return null. +
If finalMIME is not an HTML MIME type or an XML MIME type, then + return.
If {{XMLHttpRequest/responseType}} is the empty string and the final MIME type is an - HTML MIME type, then return null. +
If xhr's response type is the empty string and finalMIME is an + HTML MIME type, then return. -
This is restricted to
- {{XMLHttpRequest/responseType}} being
- "document
" in order to prevent breaking legacy
- content.
+
This is restricted to xhr's response type being
+ "document
" in order to prevent breaking legacy content.
If the final MIME type is an HTML MIME type, then: +
If finalMIME is an HTML MIME type, then:
Let charset be the final charset. +
Let charset be the result of get a final encoding for xhr.
If charset is null, prescan - the first 1024 bytes of received bytes and if + the first 1024 bytes of xhr's received bytes and if that does not terminate unsuccessfully then let charset be the return value. @@ -1380,7 +1300,7 @@ or null). Unless stated otherwise it is null.
Let document be a document that - represents the result parsing received bytes following the rules set + represents the result parsing xhr's received bytes following the rules set forth in the HTML Standard for an HTML parser with scripting disabled and a known definite encoding charset. [[!HTML]] @@ -1390,13 +1310,10 @@ or null). Unless stated otherwise it is null.
Otherwise, let document be a - document - that represents the result of running the XML parser - with XML scripting support disabled on +
Otherwise, let document be a document that represents the result of running + the XML parser with XML scripting support disabled on xhr's received bytes. If that fails (unsupported character encoding, - namespace well-formedness error, etc.), then return null. - [[!HTML]] + namespace well-formedness error, etc.), then return null. [[!HTML]]
Resources referenced will not be loaded and no associated XSLT will be applied. @@ -1404,65 +1321,41 @@ or null). Unless stated otherwise it is null.
If charset is null, then set charset to UTF-8. -
Set document's - encoding to - charset. +
Set document's encoding to charset. -
Set document's content type to the final MIME type. +
Set document's content type to finalMIME. -
Set document's origin to - context object's - relevant settings object's - origin. +
Set document's origin to xhr's + relevant settings object's origin. -
Set response object to - document and return it. +
Set xhr's response object to document.
A JSON response is the return value of these steps: +
To get a text response for an +{{XMLHttpRequest}} object xhr, run these steps:
Let jsonObject be the result of running parse JSON from bytes on - received bytes. If that threw an exception, then return null. - -
Set response object to jsonObject and return it. -
If xhr's response's body is null, + then return the empty string. -
A text response is the return value of these steps: - -
If response's - body is null, then return the - empty string. - -
Let charset be the final charset. +
Let charset be the result of get a final encoding for xhr.
If {{XMLHttpRequest/responseType}} is the empty string, charset is null, and the - final MIME type is an XML MIME type, then use the rules set forth in the XML - specifications to determine the encoding. Let charset be the determined encoding. - [[!XML]] [[!XMLNS]] +
If xhr's response type is the empty string, charset is null, and + the result of get a final MIME type for xhr is an XML MIME type, then use + the rules set forth in the XML specifications to determine the encoding. Let charset be + the determined encoding. [[!XML]] [[!XML-NAMES]] -
This is restricted to
- {{XMLHttpRequest/responseType}} being
- the empty string to keep the non-legacy
- {{XMLHttpRequest/responseType}} value
- "text
" simple.
+
This is restricted to xhr's response type being the empty string
+ to keep the non-legacy response type value "text
" simple.
If charset is null, then set charset to UTF-8. -
Return the result of running - decode on received bytes using fallback - encoding charset. +
Return the result of running decode on xhr's received bytes using + fallback encoding charset.
Authors are strongly encouraged to always encode their resources using UTF-8. @@ -1473,29 +1366,29 @@ or null). Unless stated otherwise it is null.
client . overrideMimeType(mime)
Acts as if the `Content-Type
` header value for response is mime.
- (It does not actually change the header though.)
+
Acts as if the `Content-Type
` header value for a response is mime. (It
+ does not change the header.)
Throws an "{{InvalidStateError!!exception}}" {{DOMException}} if state is loading or done.
The overrideMimeType(mime)
method,
-when invoked, must run these steps:
+
The overrideMimeType(mime)
method
+steps are:
If this's state is loading or done, then throw an "{{InvalidStateError!!exception}}" {{DOMException}}. -
Set override MIME type to the result of parsing - mime. +
Set this's override MIME type to the result of + parsing mime. -
If override MIME type is failure, then set override MIME type to
- application/octet-stream
.
+
If this's override MIME type is failure, then set this's
+ override MIME type to application/octet-stream
.
responseType
attributeresponseType
getter and setterclient . responseType [ = value ]
@@ -1519,145 +1412,137 @@ when invoked, must run these steps:
synchronous flag is set and current global object is a {{Window}} object.
The responseType
getter steps are to return
+this's response type.
-
The
-responseType
-attribute must return its value. Initially its value must be the empty
-string.
-
-
Setting the -{{XMLHttpRequest/responseType}} -attribute must run these steps: +
The {{XMLHttpRequest/responseType}} setter steps are:
If current global object is not a
- {{Window}} object and the given value is
- "document
", terminate these steps.
+
If the current global object is not a {{Window}} object and the given value is
+ "document
", then return.
-
If this's state is loading or done, then throw an "{{InvalidStateError!!exception}}" {{DOMException}}. -
If current global object is a {{Window}} object and the synchronous flag is - set, then throw an "{{InvalidAccessError!!exception}}" {{DOMException}}. +
If the current global object is a {{Window}} object and this's + synchronous flag is set, then throw an "{{InvalidAccessError!!exception}}" + {{DOMException}}. -
Set the - {{XMLHttpRequest/responseType}} - attribute's value to the given value. +
Set this's response type to the given value.
response
attributeresponse
getterThe
-response
-attribute must return the result of running these
-steps:
+
The response
getter steps are:
+
+
If this's response type is the empty string or "text
", then:
-
text
"
- If state is not - loading or done, return the empty string. +
If this's state is not loading or done, then return + the empty string. -
Return the text response. +
Return the result of getting a text response for this.
If this's response object is failure, then return null. + +
If this's response object is non-null, then return it. + +
If this's response type is "arraybuffer
", then set this's
+ response object to a new {{ArrayBuffer}} object representing this's
+ received bytes. If this throws an exception, then set this's response object
+ to failure and return null.
+
+
Allocating an {{ArrayBuffer}} object is not guaranteed to succeed. [[!ECMASCRIPT]] + +
Otherwise, if this's response type is "blob
",
+ set this's response object to a new {{Blob}} object representing
+ this's received bytes with {{Blob/type}} set to the result of
+ get a final MIME type for this.
+
+
Otherwise, if this's response type is "document
",
+ set a document response for this.
+
+
Otherwise: +
If state is not - done, return null. +
Assert: this's response type is "json
".
-
If response object is failure, then return null. +
If response object is non-null, then return it. +
Let jsonObject be the result of running parse JSON from bytes on + this's received bytes. If that threw an exception, then return null. -
arraybuffer
"
- Return the arraybuffer response. - -
blob
"
- Return the blob response. - -
document
"
- Return the document response. - -
json
"
- Return the JSON response. -
Set this's response object to jsonObject.
Return this's response object. +
responseText
attributeresponseText
getterclient . responseText
Returns the text response. +
Returns response as text.
Throws an "{{InvalidStateError!!exception}}" {{DOMException}} if
{{XMLHttpRequest/responseType}} is not the empty string or "text
".
The
-responseText
-attribute must return the result of running these
-steps:
+
The responseText
getter steps are:
If {{XMLHttpRequest/responseType}} is not the empty string or "text
", then
+
If this's response type is not the empty string or "text
", then
throw an "{{InvalidStateError!!exception}}" {{DOMException}}.
-
If state is not loading or done, then return the empty string. +
If this's state is not loading or done, then return + the empty string. -
Return the text response. +
Return the result of getting a text response for this.
responseXML
attributeresponseXML
getterclient . responseXML
Returns the document response. +
Returns the response as document.
Throws an "{{InvalidStateError!!exception}}" {{DOMException}} if
{{XMLHttpRequest/responseType}} is not the empty string or "document
".
The
-responseXML
-attribute must return the result of running these steps:
+
The responseXML
getter steps are:
If {{XMLHttpRequest/responseType}} is not the empty string or "document
", then
- throw an "{{InvalidStateError!!exception}}" {{DOMException}}.
+
If this's response type is not the empty string or "document
",
+ then throw an "{{InvalidStateError!!exception}}" {{DOMException}}.
+
+
If state is not done, then return null. +
Assert: this's response object is not failure. -
Assert: response object is not failure. +
If this's response object is non-null, then return it. -
If response object is non-null, then return it. +
Set a document response for this. -
Return the document response. +
Return this's response object.
The
-FormData(form)
-constructor must run these steps:
+new FormData(form)
+constructor steps are:
Let fd be a new {{FormData}} object. -
If form is given, then: @@ -1792,78 +1675,87 @@ constructor must run these steps:
If list is null, then throw an "{{InvalidStateError!!exception}}" {{DOMException}}. -
Set fd's entry list to list. +
Set this's entry list to list.
Return fd.
The
append(name, value)
and
append(name, blobValue, filename)
-methods, when invoked, must run these steps:
+method steps are:
Let value be value if given, and blobValue otherwise. +
Let value be value if given; otherwise blobValue.
Let entry be the result of creating an entry with name, value, and filename if given. -
Append entry to the context object's - entry list. +
Append entry to this's entry list.
The reason there is an argument named value as well as blobValue is due to a limitation of the editing software used to write the XMLHttpRequest Standard.
The delete(name)
-method, when invoked, must remove all entries whose
-name is name from the context object's
-entry list.
+method steps are to remove all entries whose
+name is name from this's entry list.
+
+
The get(name)
method
+steps are:
-
The get(name)
method,
-when invoked, must return the value of the first entry
-whose name is name from the context object's
-entry list, and null otherwise.
+
If there is no entry whose name is + name in this's entry list, then return null. + +
Return the value of the first entry whose + name is name from this's + entry list. +
The getAll(name)
-method, when invoked, must return the values of all
-entries whose name is name, in order, from
-the context object's entry list, and the empty list otherwise.
+method steps are:
+
+
If there is no entry whose name is + name in this's entry list, then return the empty list. -
The has(name)
method,
-when invoked, must return true if there is an entry whose
-name is name in the context object's
-entry list, and false otherwise.
+
Return the values of all entries whose + name is name, in order, from this's + entry list. +
The has(name)
method
+steps are to return true if there is an entry whose
+name is name in this's entry list;
+otherwise false.
The
set(name, value)
and
set(name, blobValue, filename)
-methods, when invoked, must run these steps:
+method steps are:
Let value be value if given, and blobValue otherwise. +
Let value be value if given; otherwise blobValue.
Let entry be the result of creating an entry with name, value, and filename if given. -
If there are any entries in the context object's - entry list whose name is name, then - replace the first such entry with entry and - remove the others. +
If there are entries in this's entry list + whose name is name, then replace the first + such entry with entry and remove the others. -
Otherwise, append entry to the context object's +
Otherwise, append entry to this's entry list.
The reason there is an argument named value as well as blobValue is due to a limitation of the editing software used to write the XMLHttpRequest Standard. -
The value pairs to iterate over are the context object's -entry list's entries with the key being the -name and the value being the value. +
The value pairs to iterate over are this's entry list's +entries with the key being the name and the value +being the value.
lengthComputable
,
loaded
, and
total
-attributes must return the value they were initialized to.
+getter steps are to return the value they were initialized to.
For cross-origin requests some kind of opt-in, e.g. the +
For cross-origin requests some kind of opt-in, e.g., the CORS protocol defined in the Fetch Standard, has to be used before events using the {{ProgressEvent}} interface are dispatched -as information (e.g. size) would be revealed that cannot be obtained +as information (e.g., size) would be revealed that cannot be obtained otherwise. [[!FETCH]] @@ -2015,6 +1907,7 @@ otherwise. [[!FETCH]]
Thanks to @@ -2128,7 +2021,7 @@ Zhenbin Xu for their contributions to this standard.
Special thanks to the Microsoft employees who first implemented the
-XMLHttpRequest
interface, which was first widely deployed by the
+{{XMLHttpRequest}} interface, which was first widely deployed by the
Windows Internet Explorer browser.
Special thanks to Ian Hickson for drafting an initial version of this specification in