aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/xmlhttprequest/readystate/index.html
diff options
context:
space:
mode:
authorPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
committerPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
commit33058f2b292b3a581333bdfb21b8f671898c5060 (patch)
tree51c3e392513ec574331b2d3f85c394445ea803c6 /files/zh-cn/web/api/xmlhttprequest/readystate/index.html
parent8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff)
downloadtranslated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip
initial commit
Diffstat (limited to 'files/zh-cn/web/api/xmlhttprequest/readystate/index.html')
-rw-r--r--files/zh-cn/web/api/xmlhttprequest/readystate/index.html109
1 files changed, 109 insertions, 0 deletions
diff --git a/files/zh-cn/web/api/xmlhttprequest/readystate/index.html b/files/zh-cn/web/api/xmlhttprequest/readystate/index.html
new file mode 100644
index 0000000000..c47030c9c8
--- /dev/null
+++ b/files/zh-cn/web/api/xmlhttprequest/readystate/index.html
@@ -0,0 +1,109 @@
+---
+title: XMLHttpRequest.readyState
+slug: Web/API/XMLHttpRequest/readyState
+tags:
+ - AJAX
+ - XMLHttpRequest
+translation_of: Web/API/XMLHttpRequest/readyState
+---
+<p>{{APIRef('XMLHttpRequest')}}</p>
+
+<p><strong>XMLHttpRequest.readyState</strong> 属性返回一个 XMLHttpRequest  代理当前所处的状态。一个 <abbr title="XMLHttpRequest">XHR</abbr> 代理总是处于下列状态中的一个:</p>
+
+<table class="standard-table">
+ <tbody>
+ <tr>
+ <td class="header">值</td>
+ <td class="header">状态</td>
+ <td class="header">描述</td>
+ </tr>
+ <tr>
+ <td><code>0</code></td>
+ <td><code>UNSENT</code></td>
+ <td>代理被创建,但尚未调用 open() 方法。</td>
+ </tr>
+ <tr>
+ <td><code>1</code></td>
+ <td><code>OPENED</code></td>
+ <td><code>open()</code> 方法已经被调用。</td>
+ </tr>
+ <tr>
+ <td><code>2</code></td>
+ <td><code>HEADERS_RECEIVED</code></td>
+ <td><code>send()</code> 方法已经被调用,并且头部和状态已经可获得。</td>
+ </tr>
+ <tr>
+ <td><code>3</code></td>
+ <td><code>LOADING</code></td>
+ <td>下载中; <code>responseText</code> 属性已经包含部分数据。</td>
+ </tr>
+ <tr>
+ <td><code>4</code></td>
+ <td><code>DONE</code></td>
+ <td>下载操作已完成。</td>
+ </tr>
+ </tbody>
+</table>
+
+<dl>
+ <dt>UNSENT</dt>
+ <dd>XMLHttpRequest 代理已被创建, 但尚未调用 open() 方法。</dd>
+ <dt>OPENED</dt>
+ <dd>open() 方法已经被触发。在这个状态中,可以通过  <a href="/en-US/docs/Web/API/XMLHttpRequest/setRequestHeader">setRequestHeader()</a> 方法来设置请求的头部, 可以调用 <a href="/en-US/docs/Web/API/XMLHttpRequest/send">send()</a> 方法来发起请求。</dd>
+ <dt>HEADERS_RECEIVED</dt>
+ <dd>send() 方法已经被调用,响应头也已经被接收。</dd>
+ <dt>LOADING</dt>
+ <dd>响应体部分正在被接收。如果 <code><a href="/en-US/docs/Web/API/XMLHttpRequest/responseType">responseType</a></code> 属性是“text”或空字符串, <code><a href="/en-US/docs/Web/API/XMLHttpRequest/responseText">responseText</a></code> 将会在载入的过程中拥有部分响应数据。</dd>
+ <dt>DONE</dt>
+ <dd>请求操作已经完成。这意味着数据传输已经彻底完成或失败。</dd>
+</dl>
+
+<div class="note">
+<p>在IE中,状态有着不同的名称,并不是 <code>UNSENT</code>,<code>OPENED</code> , <code>HEADERS_RECEIVED</code> , <code>LOADING</code> <code>和 DONE, 而是 READYSTATE_UNINITIALIZED</code> (0),<code>READYSTATE_LOADING</code> (1) , <code>READYSTATE_LOADED</code> (2) , <code>READYSTATE_INTERACTIVE</code> (3) <code>和 READYSTATE_COMPLETE</code> (4) 。</p>
+</div>
+
+<h2 id="示例">示例</h2>
+
+<pre class="brush: js">var xhr = new XMLHttpRequest();
+console.log('UNSENT', xhr.readyState); // readyState 为 0
+
+xhr.open('GET', '/api', true);
+console.log('OPENED', xhr.readyState); // readyState 为 1
+
+xhr.onprogress = function () {
+ console.log('LOADING', xhr.readyState); // readyState 为 3
+};
+
+xhr.onload = function () {
+ console.log('DONE', xhr.readyState); // readyState 为 4
+};
+
+xhr.send(null);
+</pre>
+
+<h2 id="规范">规范</h2>
+
+<table class="standard-table">
+ <tbody>
+ <tr>
+ <th scope="col">规范</th>
+ <th scope="col">状态</th>
+ <th scope="col">注释</th>
+ </tr>
+ <tr>
+ <td>{{SpecName('XMLHttpRequest', '#states')}}</td>
+ <td>{{Spec2('XMLHttpRequest')}}</td>
+ <td>WHATWG living standard</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="浏览器兼容性">浏览器兼容性</h2>
+
+<div class="hidden">
+<p>The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out <a href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> and send us a pull request.</p>
+</div>
+
+<p>{{Compat("api.XMLHttpRequest.readyState")}}</p>
+
+<div id="compat-mobile"> </div>