Draft This page is not complete.
The read-only XMLHttpRequest
property responseText
returns the text received from a server following a request being sent.
Syntax
var resultText = XMLHttpRequest.responseText;
Value
A DOMString
which contains either the textual data received using the XMLHttpRequest
or null
if the request failed or ""
if the request has not yet been sent by calling send()
.
While handling an asynchronous request, the value of responseText
always has the current content received from the server, even if it's incomplete because the data has not been completely received yet.
You know the entire content has been received when the value of readyState
becomes XMLHttpRequest.DONE
(4
), and status
becomes 200 ("OK"
).
Exceptions
InvalidStateError
- The
XMLHttpRequest.responseType
is not set to either the empty string or"text"
. Since theresponseText
property is only valid for text content, any other value is an error condition.
Example
var xhr = new XMLHttpRequest();
xhr.open('GET', '/server', true);
// If specified, responseType must be empty string or "text"
xhr.responseType = 'text';
xhr.onload = function () {
if (xhr.readyState === xhr.DONE) {
if (xhr.status === 200) {
console.log(xhr.response);
console.log(xhr.responseText);
}
}
};
xhr.send(null);
Specifications
Specification | Status | Comment |
---|---|---|
XMLHttpRequest | Living Standard | WHATWG living standard |
Browser compatibility
The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Update compatibility data on GitHub
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
responseText
|
Chrome
Full support 1 |
Edge
Full support 12 |
Firefox
Full support 1 |
IE Full support 5 Full support 5 Notes' Before Internet Explorer 10, the value of |
Opera
Full support 8 |
Safari
Full support 1.2 |
WebView Android
Full support 1 |
Chrome Android
Full support 18 |
Firefox Android
Full support 4 |
Opera Android
Full support 10.1 |
Safari iOS
Full support 1 |
Samsung Internet Android
Full support 1.0 |
Legend
- Full support
- Full support
- See implementation notes.'
- See implementation notes.
XMLHttpRequest.responseText by Mozilla Contributors is licensed under CC-BY-SA 2.5.