XMLHttpRequest.responseType
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 which specifies what type of data the response contains. It can take the following values:
""-
An empty
responseTypestring is 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.
Note: 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.
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.
XHR requests 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
Browser compatibility
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | |
responseType |
31 |
12 |
6 |
10 |
12-15
18
|
7 |
55 |
55 |
50 |
42 |
7 |
6.0 |
arraybuffer |
31 |
12 |
6 |
10 |
12-15
18
|
Yes |
55 |
Yes |
50 |
Yes |
? |
Yes |
blob |
31 |
12 |
6 |
10 |
18 |
Yes |
55 |
Yes |
50 |
Yes |
? |
Yes |
document |
31 |
12 |
11 |
10 |
No |
7 |
55 |
Yes |
50 |
Yes |
7 |
Yes |
json |
31 |
79 |
10 |
No |
12-15
18
|
7 |
55 |
Yes |
50 |
? |
7 |
Yes |
moz-blob |
No |
No |
12-58 |
No |
No |
No |
No |
No |
No |
No |
No |
No |
moz-chunked-arraybuffer |
No |
No |
14-68 |
No |
No |
No |
No |
No |
50-68 |
No |
No |
No |
See also
- Using XMLHttpRequest
- HTML in XMLHttpRequest
- The response data:
response,responseText, andresponseXML
© 2005–2021 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/responseType