XMLHttpRequest.readyState property returns the state an XMLHttpRequest client is in. An XHR client exists in one of the following states:

状态 描述
0 UNSENT Client has been created. open() not called yet.
1 OPENED open() has been called.
2 HEADERS_RECEIVED send() has been called, and headers and status are available.
3 LOADING Downloading; responseText holds partial data.
4 DONE The operation is complete.
UNSENT

The XMLHttpRequest client has been created, but the open() method hasn't been called yet.

OPENED
open() method has been invoked. During this state, the request headers can be set using the setRequestHeader() 方法和 send() method can be called which will initiate the fetch.
HEADERS_RECEIVED

send() has been called and the response headers have been received.

LOADING
Response's body is being received. If responseType is "text" or empty string, responseText will have the partial text response as it loads.
DONE

The fetch operation is complete. This could mean that either the data transfer has been completed successfully or failed.

The state names are different in versions of Internet Explorer earlier than 11. Instead of UNSENT , OPENED , HEADERS_RECEIVED , LOADING and DONE , the names READYSTATE_UNINITIALIZED (0), READYSTATE_LOADING (1), READYSTATE_LOADED (2), READYSTATE_INTERACTIVE (3) and READYSTATE_COMPLETE (4) are used.

范例

var xhr = new XMLHttpRequest();
console.log('UNSENT', xhr.readyState); // readyState will be 0
xhr.open('GET', '/api', true);
console.log('OPENED', xhr.readyState); // readyState will be 1
xhr.onprogress = function () {
    console.log('LOADING', xhr.readyState); // readyState will be 3
};
xhr.onload = function () {
    console.log('DONE', xhr.readyState); // readyState will be 4
};
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
readyState Chrome 1 Edge 12 Firefox 1 IE 7 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
constants Chrome Yes Edge 12 Firefox 9 IE 9 Opera 12 Safari Yes WebView Android Yes Chrome Android 18 Firefox Android 9 Opera Android Yes Safari iOS ? Samsung Internet Android 1.0

图例

完整支持

完整支持

兼容性未知 ?

兼容性未知

元数据

  • 最后修改: