Response: statusText property
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.
Note: This feature is available inWeb Workers.
ThestatusText read-only property of theResponse interface contains the status message corresponding to the HTTP status code inResponse.status.
For example, this would beOK for a status code200,Continue for100,Not Found for404.
In this article
Value
AString containing the HTTP status message associated with the response.The default value is "".
SeeHTTP response status codes for a list of codes and their associated status messages.Note that HTTP/2does not support status messages.
Examples
In ourFetch Response example (seeFetch Response live) we create a newRequest object using theRequest() constructor, passing it a JPG path.We then fetch this request usingfetch(), extract a blob from the response usingResponse.blob, create an object URL out of it usingURL.createObjectURL(), and display this in an<img>.
Note that at the top of thefetch() block we log the responsestatusText value to the console.
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; });Specifications
| Specification |
|---|
| Fetch> # ref-for-dom-response-statustext①> |