1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| const controller = new AbortController(); let signal = controller.signal; console.log('signal 的初始状态: ', signal);
const downloadBtn = document.querySelector('.download'); const abortBtn = document.querySelector('.abort');
downloadBtn.addEventListener('click', function(){ fetch(url, {signal}).then(function(response) { }).catch(function(e) { console.log('Download error: ' + e.message); }) });
abortBtn.addEventListener('click', function() { controller.abort(); console.log('signal 的中止状态: ', signal); });
|