Movatterモバイル変換


[0]ホーム

URL:


  1. Web
  2. Web APIs
  3. XMLHttpRequest
  4. responseType

XMLHttpRequest: responseType property

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since ⁨November 2016⁩.

Note: This feature is available inWeb Workers, except forService Workers.

TheXMLHttpRequest propertyresponseType is an enumerated string value specifyingthe type of data contained in the response.

It also lets the author change theresponse type. If an empty string is set as the value ofresponseType, thedefault value oftext is used.

Value

A string which specifies what type of data the response contains.It can take the following values:

""

An emptyresponseType string is the same as"text", the default type.

"arraybuffer"

Theresponse is a JavaScriptArrayBuffer containing binary data.

"blob"

Theresponse is aBlob object containing the binary data.

"document"

Theresponse is anHTMLDocument orXMLXMLDocument, as appropriate based on the MIME type of the received data. SeeHTML in XMLHttpRequest to learn more about using XHR to fetch HTML content.

"json"

Theresponse is a JavaScript object created by parsing the contents of received data asJSON.

"text"

Theresponse is a text in a string.

Note:When settingresponseType to a particular value, the author should makesure that the server is actually sending a response compatible with that format. Ifthe server returns data that is not compatible with theresponseType thatwas set, the value ofresponse will benull.

Exceptions

InvalidAccessErrorDOMException

An attempt was made to change the value ofresponseType onanXMLHttpRequest which is in synchronous mode but not in aWorker. For additional details, seeSynchronous XHR restrictions below.

Usage notes

Synchronous XHR restrictions

You cannot change the value ofresponseType in a synchronousXMLHttpRequest except when the request belongs to aWorker.This restriction is designed in part to help ensure that synchronous operations aren'tused for large transactions that block the browser's main thread, thereby bogging downthe user experience.

XHR requests are asynchronous by default; they are only placed insynchronous mode by passingfalse as the value of the optionalasync parameter when callingopen().

Restrictions in Workers

Attempts to set the value ofresponseType todocument areignored in aWorker.

Specifications

Specification
XMLHttpRequest
# the-responsetype-attribute

Browser compatibility

See also

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp