Response: statusText プロパティ

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since March 2017.

statusTextResponse インターフェイスの読み取り専用プロパティで、 Response.status にある HTTP ステータスコードに対応するステータスメッセージを保持します。

例えば、ステータスコード 200 に対しては OK100 に対しては Continue404 に対しては Not Found です。

文字列で、レスポンスに関連する HTTP ステータスメッセージを保持します。 既定値は "" です。

コードと関連するステータスメッセージの一覧は、 HTTP レスポンスステータスコードを参照してください。 なお、 HTTP/2 はステータスメッセージに対応していません

Fetch Response の例Fetch Response のライブ版 を参照)では、新しい Request オブジェクトを、 Request() コンストラクターを使用して作成し、 JPG のパスを渡します。次に fetch() を使用してこのリクエストをフェッチし、 Response.blob を使用してリクエストから blob を抽出し、 URL.createObjectURL() を使用してオブジェクト URL を作成し、これを <img> に表示します。

なお、 fetch() ブロックの先頭で、レスポンスの statusText 値をコンソールにログ出力していることに注意してください。

js
const myImage = document.querySelector("img");

const myRequest = new Request("flowers.jpg");

fetch(myRequest)
  .then((response) => {
    console.log("response.statusText =", response.statusText); // response.statusText = "OK"
    return response.blob();
  })
  .then((myBlob) => {
    const objectURL = URL.createObjectURL(myBlob);
    myImage.src = objectURL;
  });

仕様書

Specification
Fetch
# ref-for-dom-response-statustext①

ブラウザーの互換性

Report problems with this compatibility data on GitHub
desktopmobileserver
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
Node.js
statusText

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

関連情報