aboutsummaryrefslogtreecommitdiff
path: root/files/zh-tw/web/api/xmlhttprequest/status/index.html
blob: bd62ed68fd18d1ccc3233f2519f61a2473dcf620 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
---
title: XMLHttpRequest.status
slug: Web/API/XMLHttpRequest/status
translation_of: Web/API/XMLHttpRequest/status
---
<div>{{APIRef('XMLHttpRequest')}}</div>

<p><strong>XMLHttpRequest.status</strong> 屬性根據XMLHttpRequest的回應傳回數值化的狀況編碼。狀況編碼為一正短整數(<code>unsigned short)。</code>Before the request is complete, the value of <code>status</code> will be <code>0</code>. It is worth noting that browsers report a status of 0 in case of XMLHttpRequest errors too.</p>

<p>The status codes returned are the standard <a href="/en-US/docs/Web/HTTP/Response_codes">HTTP status codes</a>. For example, <code>status</code> <code>200</code> denotes a successful request. If the server response doesn't explicitly specify a status code, <code>XMLHttpRequest.status</code> will assume the default value of <code>200</code>.</p>

<h2 id="Example">Example</h2>

<pre class="brush: js">var xhr = new XMLHttpRequest();
console.log('UNSENT', xhr.status);

xhr.open('GET', '/server', true);
console.log('OPENED', xhr.status);

xhr.onprogress = function () {
  console.log('LOADING', xhr.status);
};

xhr.onload = function () {
  console.log('DONE', xhr.status);
};

xhr.send(null);

/**
 * Outputs the following:
 *
 * UNSENT 0
 * OPENED 0
 * LOADING 200
 * DONE 200
 */
</pre>

<h2 id="Specifications">Specifications</h2>

<table class="standard-table">
 <tbody>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
  <tr>
   <td>{{SpecName('XMLHttpRequest', '#the-status-attribute')}}</td>
   <td>{{Spec2('XMLHttpRequest')}}</td>
   <td>WHATWG living standard</td>
  </tr>
 </tbody>
</table>

<h2 id="Browser_compatibility">Browser compatibility</h2>

{{Compat("api.XMLHttpRequest.status")}}

<h2 id="See_also">See also</h2>

<ul>
 <li>List of <a href="/en-US/docs/Web/HTTP/Response_codes">HTTP response codes</a></li>
</ul>