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 July 2015.
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 |
ブラウザーの互換性
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
status |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
The compatibility table on 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.
関連情報
- HTTP ステータスの一覧
- HTTP