GO-Ve01
ServicesDevelopersBooksDictionaryPapersWikidataEncyclopediaSearchBabelCareersDeck

XMLHttpRequest: responseType property

XMLHttpRequest API windowandworkerexceptservice

XMLHttpRequest API window_and_worker_except_service

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.

## Value

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

- `""`
- : An empty `responseType` string is the same as `"text"`, the default type.
- `"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](/docs/Web/API/XMLHttpRequest_API/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 a text in a string.

> [!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` DOMException
- : An attempt was made to change the value of `responseType` on
an `XMLHttpRequest` which is in synchronous mode but not in a
Worker. For additional details, see [Synchronous XHR restrictions](#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

## See also

- [Using XMLHttpRequest](/docs/Web/API/XMLHttpRequest_API/Using_XMLHttpRequest)
- [HTML in XMLHttpRequest](/docs/Web/API/XMLHttpRequest_API/HTML_in_XMLHttpRequest)
- The response data: response,
responseText, and
responseXML

source: MDN Web Docs mirror · page

Cite this

"XMLHttpRequest: responseType property". MDN Web Docs. CC BY-SA 2.5 (MDN). https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/responseType

JSON record · API collection · BibTeX · RIS · CSL-JSON · citation policy

Save to pass ·