XMLHttpRequest.status
XMLHttpRequest.status
プロパティは読み取り専用で、 XMLHttpRequest
のレスポンスにおける数値の HTTP ステータスコードを返します。
リクエストが完了する前は、 status
の値は 0 になります。 XMLHttpRequest
がエラーになった場合も、ブラウザーはステータスとして 0 を返します。
例
var xhr = new XMLHttpRequest();
console.log('UNSENT: ', xhr.status);
xhr.open('GET', '/server');
console.log('OPENED: ', xhr.status);
xhr.onprogress = function () {
console.log('LOADING: ', xhr.status);
};
xhr.onload = function () {
console.log('DONE: ', xhr.status);
};
xhr.send();
/**
* Outputs the following:
*
* UNSENT: 0
* OPENED: 0
* LOADING: 200
* DONE: 200
*/
仕様書
仕様書 | 状態 | 備考 |
---|---|---|
XMLHttpRequest | 現行の標準 | WHATWG living standard |
ブラウザーの互換性
BCD tables only load in the browser