The XMLHttpRequest
property responseType
is an enumerated string value specifying the type of data contained in the response. It also lets the author change the response type. If an empty string is set as the value of responseType
, the default value of "text"
is used.
var type = XMLHttpRequest.responseType; XMLHttpRequest.responseType = type;
A string taken from the XMLHttpRequestResponseType
enum which specifies what type of data the response contains.
When setting responseType
to a particular value, the author should make sure that the server is actually sending a response compatible with that format. If the server returns data that is not compatible with the responseType
that was set, the value of response
will be null
.
The values supported by responseType
are the following:
Value | Description |
---|---|
"" | An empty responseType string is treated the same as "text" , the default type (therefore, as a DOMString . |
"arraybuffer" | The response is a JavaScript ArrayBuffer containing binary data. |
"blob" | The response is a Blob object containing the binary data. |
"document" | The response is an HTML Document or XML XMLDocument , as appropriate based on the MIME type of the received data. See HTML in XMLHttpRequest to learn more about using XHR to fetch HTML content. |
"json" | The response is a JavaScript object created by parsing the contents of received data as JSON. |
"text" | The response is text in a DOMString object. |
"moz-chunked-arraybuffer"
| Similar to Accessing |
"ms-stream"
| The response is part of a streaming download; this response type is only allowed for download requests, and is only supported by Internet Explorer. |
InvalidAccessError
responseType
on anXMLHttpRequest
which is in synchronous mode but not in a Worker
. For additional details, see Synchronous XHR restrictions below.You cannot change the value of responseType
in a synchronous XMLHttpRequest
except when the request belongs to a Worker
. This restriction is designed in part to help ensure that synchronous operations aren't used for large transactions that block the browser's main thread, thereby bogging down the user experience.
XMLHttpRequest
s are asynchronous by default; they are only placed in synchronous mode by passing false
as the value of the optional async
parameter when calling open()
.
Attempts to set the value of responseType
to "document"
are ignored in a Worker
.
Specification | Status | Comment |
---|---|---|
XMLHttpRequest | Living Standard | WHATWG living standard |
Desktop | ||||||
---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | |
Basic support | 31 | 12 | 6 | 10 | 18 | 7 |
arraybuffer |
10 | Yes | 6 | 10 | 18 | Yes |
blob |
19 | Yes | 6 | 10 | 12 | Yes |
document |
18 | Yes | 11 | 10 | No | 6.1 |
json |
31 | No | 10 | No | 17
|
6.1 |
moz-blob |
No | No | 12 — 58 | No | No | No |
Mobile | |||||||
---|---|---|---|---|---|---|---|
Android webview | Chrome for Android | Edge Mobile | Firefox for Android | Opera for Android | iOS Safari | Samsung Internet | |
Basic support | 55 | 55 | Yes | 50 | Yes | ? | 6.0 |
arraybuffer |
Yes | Yes | Yes | 50 | Yes | ? | Yes |
blob |
Yes | Yes | Yes | 50 | Yes | ? | Yes |
document |
Yes | Yes | Yes | 50 | Yes | ? | Yes |
json |
Yes | Yes | No | 50 | ? | ? | Yes |
moz-blob |
No | No | No | No | No | No | No |
response
, responseText
, and responseXML
© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/responseType