Response: status-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 schreibgeschützte status-Eigenschaft des Response-Interfaces enthält die HTTP-Statuscodes der Antwort.

Zum Beispiel 200 für Erfolg, 404, wenn die Ressource nicht gefunden werden konnte.

Wert

Eine nicht signierte kurze Zahl. Dies ist einer der HTTP-Antwortstatuscodes.

Beispiele

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

Beachten Sie, dass wir am Anfang des fetch()-Blocks den status-Wert der Antwort in der Konsole protokollieren.

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

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

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

Spezifikationen

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

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
status

Legend

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

Full support
Full support

Siehe auch