The XMLHttpRequest.abort()
method aborts the request if it has already been sent. When a request is aborted, its readyState
is changed to XMLHttpRequest.UNSENT
(0) and the request's status
code is set to 0.
The XMLHttpRequest.abort()
method aborts the request if it has already been sent. When a request is aborted, its readyState
is changed to XMLHttpRequest.UNSENT
(0) and the request's status
code is set to 0.
js
abort()
None.
None (undefined
).
This example begins loading content from the MDN home page, then due to some condition, aborts the transfer by calling abort()
.
js
const xhr = new XMLHttpRequest(); const method = "GET"; const url = "https://developer.mozilla.org/"; xhr.open(method, url, true); xhr.send(); if (OH_NOES_WE_NEED_TO_CANCEL_RIGHT_NOW_OR_ELSE) { xhr.abort(); }
Specification |
---|
XMLHttpRequest Standard # the-abort()-method |
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | |
abort |
1 | 12 | 1 | 5 | ≤12.1 | 1.2 | 4.4 | 18 | 4 | ≤12.1 | 1 | 1.0 |
© 2005–2023 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/abort