aboutsummaryrefslogtreecommitdiff
path: root/files/zh-tw/web/api/xmlhttprequest/readystate
diff options
context:
space:
mode:
authorPeter Bengtsson <mail@peterbe.com>2020-12-08 14:43:23 -0500
committerPeter Bengtsson <mail@peterbe.com>2020-12-08 14:43:23 -0500
commit218934fa2ed1c702a6d3923d2aa2cc6b43c48684 (patch)
treea9ef8ac1e1b8fe4207b6d64d3841bfb8990b6fd0 /files/zh-tw/web/api/xmlhttprequest/readystate
parent074785cea106179cb3305637055ab0a009ca74f2 (diff)
downloadtranslated-content-218934fa2ed1c702a6d3923d2aa2cc6b43c48684.tar.gz
translated-content-218934fa2ed1c702a6d3923d2aa2cc6b43c48684.tar.bz2
translated-content-218934fa2ed1c702a6d3923d2aa2cc6b43c48684.zip
initial commit
Diffstat (limited to 'files/zh-tw/web/api/xmlhttprequest/readystate')
-rw-r--r--files/zh-tw/web/api/xmlhttprequest/readystate/index.html148
1 files changed, 148 insertions, 0 deletions
diff --git a/files/zh-tw/web/api/xmlhttprequest/readystate/index.html b/files/zh-tw/web/api/xmlhttprequest/readystate/index.html
new file mode 100644
index 0000000000..3f7e909fe0
--- /dev/null
+++ b/files/zh-tw/web/api/xmlhttprequest/readystate/index.html
@@ -0,0 +1,148 @@
+---
+title: XMLHttpRequest.readyState
+slug: Web/API/XMLHttpRequest/readyState
+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>客戶端已被建立,但 <code>open()</code> 方法尚未被呼叫。</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> 方法已被呼叫,而且可取得 header 與狀態。</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="/zh-TW/docs/Web/API/XMLHttpRequest/setRequestHeader">setRequestHeader()</a> 方法設定請求標頭(request headers),並可呼叫 <a href="/zh-TW/docs/Web/API/XMLHttpRequest/send">send()</a> 方法來發送請求。</dd>
+ <dt>HEADERS_RECEIVED</dt>
+ <dd>send() 方法已被呼叫,並且已接收到回應標頭(response header)。</dd>
+ <dt>LOADING</dt>
+ <dd>正在接收回應內容(response's body)。如 <code><a href="/zh-TW/docs/Web/API/XMLHttpRequest/responseType">responseType</a></code> 屬性為 "text" 或空字串,則 <code><a href="/zh-TW/docs/Web/API/XMLHttpRequest/responseText">responseText</a></code> 屬性將會在載入的過程中擁有已載入部分之回應(response)內容中的文字。</dd>
+ <dt>DONE</dt>
+ <dd>請求操作已完成。這意味著資料傳輸可能已成功完成或是已失敗。</dd>
+</dl>
+
+<div class="note">
+<p>這些狀態名稱在 Internet Explorer 中略有不同。其中 <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 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);
+</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>{{CompatibilityTable}}</div>
+
+<div id="compat-desktop">
+<table class="compat-table">
+ <tbody>
+ <tr>
+ <th>功能</th>
+ <th>Chrome</th>
+ <th>Firefox (Gecko)</th>
+ <th>Internet Explorer</th>
+ <th>Opera</th>
+ <th>Safari (WebKit)</th>
+ </tr>
+ <tr>
+ <td>基本支援</td>
+ <td>{{CompatChrome(1)}}</td>
+ <td>{{CompatGeckoDesktop("1.0")}}<sup>[1]</sup></td>
+ <td>{{CompatIe(7)}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatSafari("1.2")}}</td>
+ </tr>
+ </tbody>
+</table>
+</div>
+
+<div id="compat-mobile">
+<table class="compat-table">
+ <tbody>
+ <tr>
+ <th>功能</th>
+ <th>Android</th>
+ <th>Chrome for Android</th>
+ <th>Firefox Mobile (Gecko)</th>
+ <th>IE Mobile</th>
+ <th>Opera Mobile</th>
+ <th>Safari Mobile</th>
+ </tr>
+ <tr>
+ <td>基本支援</td>
+ <td>{{CompatUnknown}}</td>
+ <td>1.0</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatUnknown}}</td>
+ </tr>
+ </tbody>
+</table>
+</div>