loading...

re: Aborting a fetch request VIEW POST

FULL DISCUSSION
 

Comparing between fetch and XMLHttpRequest for extra information:

Fetch

const controller = new AbortController;

fetch('/foo/bar', {
    signal: controller.signal
}).then(response => {
    if (response.ok) {
        alert(response.text());
    }
});

// Abort!
controller.abort();

XHR

const xhr = new XMLHttpRequest;

xhr.addEventListener('load', () => {
    if (xhr.status === 200) {
        xhr.responseType = 'text';
        alert(xhr.response);
    }
});

xhr.open('GET', '/foo/bar');
xhr.send();

// Abort!
xhr.abort();
Code of Conduct Report abuse