XMLHttpRequest: status プロパティ
Baseline
Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since 2015年7月.
XMLHttpRequest.status プロパティは読み取り専用で、 XMLHttpRequest のレスポンスにおける数値の HTTP ステータスコードを返します。
リクエストが完了する前は、 status の値は 0 になります。 XMLHttpRequest がエラーになった場合も、ブラウザーはステータスとして 0 を返します。
値
数値です。
例
js
const xhr = new XMLHttpRequest();
console.log("UNSENT: ", xhr.status);
xhr.open("GET", "/server");
console.log("OPENED: ", xhr.status);
xhr.onprogress = () => {
console.log("LOADING: ", xhr.status);
};
xhr.onload = () => {
console.log("DONE: ", xhr.status);
};
xhr.send();
/**
* 出力結果は以下の通り。
*
* UNSENT: 0
* OPENED: 0
* LOADING: 200
* DONE: 200
*/
仕様書
| Specification |
|---|
| XMLHttpRequest> # the-status-attribute> |
ブラウザーの互換性
Loading…
関連情報
- HTTP ステータスの一覧
- HTTP