Response: statusText-Eigenschaft

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.

Hinweis: Diese Funktion ist in Web Workers verfügbar.

Die statusText schreibgeschützte Eigenschaft der Response Schnittstelle enthält die Statusmeldung, die dem HTTP-Statuscode in Response.status entspricht.

Zum Beispiel wäre dies OK für den Statuscode 200, Continue für 100, Not Found für 404.

Wert

Ein String, der die HTTP-Statusmeldung enthält, die mit der Antwort verknüpft ist. Der Standardwert ist "".

Siehe HTTP-Statuscodes der Antworten für eine Liste der Codes und ihrer zugehörigen Statusmeldungen. Beachten Sie, dass HTTP/2 keine Statusmeldungen unterstützt.

Beispiele

In unserem Fetch Response-Beispiel (siehe Fetch Response live) erstellen wir ein neues Request Objekt mit dem Request() Konstruktor, dem wir einen JPG-Pfad übergeben. Wir holen diese Anforderung dann mit fetch(), extrahieren ein Blob aus der Antwort mit Response.blob, erstellen eine Objekt-URL daraus mit URL.createObjectURL(), und zeigen dies in einem <img> an.

Beachten Sie, dass wir zu Beginn des fetch()-Blocks den statusText-Wert der Antwort in die Konsole protokollieren.

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;
  });

Spezifikationen

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

Browser-Kompatibilität

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

Siehe auch