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.
Syntax
var type = XMLHttpRequest.responseType; XMLHttpRequest.responseType = type;
Value
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:
""- An empty
responseTypestring is treated the same as"text", the default type. arraybuffer- The
responseis a JavaScriptArrayBuffercontaining binary data. blob- The
responseis aBlobobject containing the binary data. document- The
responseis an HTMLDocumentor XMLXMLDocument, 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
responseis a JavaScript object created by parsing the contents of received data as JSON. text- The
responseis a text in aDOMStringobject. ms-stream- The
responseis part of a streaming download; this response type is only allowed for download requests, and is only supported by Internet Explorer.
Exceptions
InvalidAccessError- An attempt was made to change the value of
responseTypeon anXMLHttpRequestwhich is in synchronous mode but not in aWorker. For additional details, see Synchronous XHR restrictions below.
Usage notes
Synchronous XHR restrictions
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.
XMLHttpRequests 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().
Restrictions in Workers
Attempts to set the value of responseType to document are ignored in a Worker.
Specifications
| Specification | Status | Comment |
|---|---|---|
| XMLHttpRequest | Living Standard | WHATWG living standard |
Browser compatibility
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
responseType | Chrome Full support 31 | Edge Full support 12 | Firefox Full support 6 | IE Full support 10 | Opera Full support 18 | Safari Full support 7 | WebView Android Full support 55 | Chrome Android Full support 55 | Firefox Android Full support 50 | Opera Android Full support 42 | Safari iOS Full support 7 | Samsung Internet Android Full support 6.0 |
arraybuffer | Chrome Full support 31 | Edge Full support 12 | Firefox Full support 6 | IE Full support 10 | Opera Full support 18 | Safari Full support Yes | WebView Android Full support Yes | Chrome Android Full support Yes | Firefox Android Full support 50 | Opera Android Full support Yes | Safari iOS ? | Samsung Internet Android Full support Yes |
blob | Chrome Full support 31 | Edge Full support 12 | Firefox Full support 6 | IE Full support 10 | Opera Full support 18 | Safari Full support Yes | WebView Android Full support Yes | Chrome Android Full support Yes | Firefox Android Full support 50 | Opera Android Full support Yes | Safari iOS ? | Samsung Internet Android Full support Yes |
document | Chrome Full support 31 | Edge Full support 12 | Firefox Full support 11 | IE Full support 10 | Opera No support No | Safari Full support 7 | WebView Android Full support Yes | Chrome Android Full support Yes | Firefox Android Full support 50 | Opera Android Full support Yes | Safari iOS ? | Samsung Internet Android Full support Yes |
json | Chrome Full support 31 | Edge Full support 79 | Firefox Full support 10 | IE No support No | Opera Full support 18 | Safari Full support 7 | WebView Android Full support Yes | Chrome Android Full support Yes | Firefox Android Full support 50 | Opera Android ? | Safari iOS ? | Samsung Internet Android Full support Yes |
moz-blob | Chrome No support No | Edge No support No | Firefox No support 12 — 58 | IE No support No | Opera No support No | Safari No support No | WebView Android No support No | Chrome Android No support No | Firefox Android No support No | Opera Android No support No | Safari iOS No support No | Samsung Internet Android No support No |
moz-chunked-arraybuffer | Chrome No support No | Edge No support No | Firefox No support 14 — 68 | IE No support No | Opera No support No | Safari No support No | WebView Android No support No | Chrome Android No support No | Firefox Android No support 50 — 68 | Opera Android No support No | Safari iOS No support No | Samsung Internet Android No support No |
Legend
- Full support
- Full support
- No support
- No support
- Compatibility unknown
- Compatibility unknown
- Non-standard. Expect poor cross-browser support.
- Non-standard. Expect poor cross-browser support.
- Deprecated. Not for use in new websites.
- Deprecated. Not for use in new websites.
See also
- Using XMLHttpRequest
- HTML in XMLHttpRequest
- The response data:
response,responseText, andresponseXML
