responseType property
Describes the data type of the response associated with the request.
This property is read/write.
![]() |
Syntax
| JavaScript |
|---|
object.responseType = ptr ptr = object.responseType |
Property values
Type: DOMString
One of the following values:
| Value | Condition |
|---|---|
|
The response is an array buffer. |
|
The response is binary data. |
|
The response is a document. |
|
The response is part of a streaming download. This value is supported only for download requests. |
|
The response is text. |
Examples
The following example uses the responseType property to request binary data from the server.
var xhr = new XMLHttpRequest(); xhr.open("GET", "download?name=" + name, true); xhr.responseType = "blob"; xhr.onreadystatechange = function () { if (xhr.readyState == xhr.DONE) { var blob = xhr.reponse; var image = document.getElementById("my-image"); image.addEventListener("load", function (evt) { URL.revokeObjectURL(evt.target.src); } image.src = URL.createObjectURL(blob); } } xhr.send();
See also
Show:
