この記事はまだボランティアによって 日本語 に翻訳されていません。ぜひ MDN に参加して翻訳を手伝ってください!
この記事を English (US) で読むこともできます。

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 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
Similar to "arraybuffer", but the data is received in a stream. When using this response type, the value in response is only available in the handler for the progress event, and only contains the data received since the last progress event, rather than the cumulative data received since the request was sent.
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.

Exceptions

InvalidAccessError
An attempt was made to change the value of responseType on anXMLHttpRequest which is in synchronous mode but not in a Worker. 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

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
responseTypeChrome Full support 31Edge Full support 12Firefox Full support 6IE Full support 10Opera Full support 18Safari Full support 7WebView Android Full support 55Chrome Android Full support 55Firefox Android Full support 50Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support 6.0
arraybufferChrome Full support 31Edge Full support YesFirefox Full support 6IE Full support 10Opera Full support 18Safari Full support YesWebView Android Full support YesChrome Android Full support YesFirefox Android Full support 50Opera Android Full support YesSafari iOS ? Samsung Internet Android Full support Yes
blobChrome Full support 31Edge Full support YesFirefox Full support 6IE Full support 10Opera Full support 18Safari Full support YesWebView Android Full support YesChrome Android Full support YesFirefox Android Full support 50Opera Android Full support YesSafari iOS ? Samsung Internet Android Full support Yes
documentChrome Full support 31Edge Full support YesFirefox Full support 11IE Full support 10Opera No support NoSafari Full support 7WebView Android Full support YesChrome Android Full support YesFirefox Android Full support 50Opera Android Full support YesSafari iOS ? Samsung Internet Android Full support Yes
jsonChrome Full support 31Edge No support NoFirefox Full support 10IE No support NoOpera Full support 18Safari Full support 7WebView Android Full support YesChrome Android Full support YesFirefox Android Full support 50Opera Android ? Safari iOS ? Samsung Internet Android Full support Yes
moz-blob
Non-standard
Chrome No support NoEdge No support NoFirefox No support 12 — 58IE No support NoOpera No support NoSafari No support NoWebView Android No support NoChrome Android No support NoFirefox Android No support NoOpera Android No support NoSafari iOS No support NoSamsung Internet Android No support No
moz-chunked-arraybuffer
DeprecatedNon-standard
Chrome No support NoEdge No support NoFirefox No support 14 — 68IE No support NoOpera No support NoSafari No support NoWebView Android No support NoChrome Android No support NoFirefox Android No support 50 — 68Opera Android No support NoSafari iOS No support NoSamsung 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

ドキュメントのタグと貢献者

最終更新者: Rob W,