Draft
This page is not complete.
The XMLHttpRequest.response
property returns the response's body. It can be of the type ArrayBuffer, Blob, Document, JavaScript object, or a DOMString, depending of the value of XMLHttpRequest.responseType property. Value of response
is null if the request is not complete or was not successful. However, if the value of responseType
was set to "text" or the empty string, response
can contain the partial text response while the request is still in the loading state.
Value of responseType
| Data type of response property |
---|---|
"" |
DOMString (this is the default value) |
"arraybuffer" | ArrayBuffer |
"blob" | Blob |
"document" | Document |
"json" | JavaScript object, parsed from a JSON string returned by the server |
"text" | DOMString |
"moz-blob"
| Used by Firefox to allow retrieving partial Blob data from progress events. This lets your progress event handler start processing data while it's still being received. |
"moz-chunked-text"
| Similar to When This mode currently only works in Firefox. |
"moz-chunked-arraybuffer"
| Similar to When This mode currently only works in Firefox. |
"ms-stream" | Indicates that the response is part of a streaming download. It is supported only for download requests. This mode is available only in Internet Explorer. |
Note: Starting with Gecko 11.0 (Firefox 11.0 / Thunderbird 11.0 / SeaMonkey 2.8), as well as WebKit build 528, these browsers no longer let you use the responseType
attribute when performing synchronous requests. Attempting to do so throws an NS_ERROR_DOM_INVALID_ACCESS_ERR
exception. This change has been proposed to the W3C for standardization.
var url = 'somePage.html'; //A local page function load(url, callback) { var xhr = new XMLHttpRequest(); xhr.onreadystatechange = function() { if (xhr.readyState === 4) { console.log(xhr.response); //Outputs a DOMString by default } } xhr.open('GET', url, true); xhr.send(''); }
Specification | Status | Comment |
---|---|---|
XMLHttpRequest | Living Standard | WHATWG living standard |
Feature | Chrome | Edge | Firefox (Gecko) | Internet Explorer | Opera | Safari (WebKit) |
---|---|---|---|---|---|---|
Basic support | ? | (Yes) | ? | ? | ? | ? |
Feature | Android | Chrome for Android | Edge | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|---|
Basic support | ? | ? | (Yes) | ? | ? | ? | ? |
© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/response