Anfrage: signal-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 2019.
Hinweis: Dieses Feature ist verfügbar in Web Workers.
Die schreibgeschützte signal
-Eigenschaft der Request
-Schnittstelle gibt das mit der Anfrage verknüpfte AbortSignal
zurück.
Wert
Ein AbortSignal
-Objekt.
Beispiele
js
// Create a new abort controller
const controller = new AbortController();
// Create a request with this controller's AbortSignal object
const req = new Request("/", { signal: controller.signal });
// Add an event handler logging a message in case of abort
req.signal.addEventListener("abort", () => {
console.log("abort");
});
// In case of abort, log the AbortSignal reason, if any
fetch(req).catch(() => {
if (req.signal.aborted) {
if (req.signal.reason) {
console.log(`Request aborted with reason: ${req.signal.reason}`);
} else {
console.log("Request aborted but no reason was given.");
}
} else {
console.log("Request not aborted, but terminated abnormally.");
}
});
// Actually abort the request
controller.abort();
Spezifikationen
Specification |
---|
Fetch Standard # ref-for-dom-request-signal② |
Browser-Kompatibilität
BCD tables only load in the browser