-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fecth应该封装个中止请求 #1778
Comments
可以提需求给 whatwg/fetch 。 |
我也遇到这个问题点 #1838 |
var controller = new AbortController();
var signal = controller.signal;
var downloadBtn = document.querySelector('.download');
var abortBtn = document.querySelector('.abort');
downloadBtn.addEventListener('click', fetchVideo);
abortBtn.addEventListener('click', function() {
controller.abort();
console.log('Download aborted');
});
function fetchVideo() {
...
fetch(url, {signal}).then(function(response) {
...
}).catch(function(e) {
reports.textContent = 'Download error: ' + e.message;
})
} |
关于如何取消 fetch,曾有过许多讨论,也有很多的方案被提出来。 1 最初的讨论:whatwg/fetch#27 |
页面离开之后,要关闭一些正在等待中的请求,所以要中断这些无用的请求
The text was updated successfully, but these errors were encountered: