草案
此页面不完整。

只读 XMLHttpRequest property responseText returns the text received from a server following a request being sent.

句法

var resultText = XMLHttpRequest.responseText;
					

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 ),和 status becomes 200 ( "OK" ).

异常

InvalidStateError
XMLHttpRequest.responseType is not set to either the empty string or "text" . Since the responseText property is only valid for text content, any other value is an error condition.

范例

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);
					

规范

规范 状态 注释
XMLHttpRequest 实时标准 WHATWG (Web 超文本应用程序技术工作组) 实时标准

浏览器兼容性

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. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
responseText Chrome 1 Edge 12 Firefox 1 IE 5
5
Before Internet Explorer 10, the value of XMLHttpRequest.responseText could be read only once the request was complete.
Opera 8 Safari 1.2 WebView Android 1 Chrome Android 18 Firefox Android 4 Opera Android 10.1 Safari iOS 1 Samsung Internet Android 1.0

图例

完整支持

完整支持

见实现注意事项。

元数据

  • 最后修改: