Created
April 9, 2019 05:52
-
-
Save goofmint/5ce5bf07c62c3d6471cb18b78bd2a15d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
document.addEventListener('DOMContentLoaded', async (e) => { | |
let controller = new AbortController(); | |
document.querySelector('#button').onclick = async (e) => { | |
try { | |
const signal = controller.signal; | |
const result = await fetch('/json', {signal}); | |
document.querySelector('#result').innerText = JSON.stringify(await result.json()); | |
} catch (e) { | |
console.log(e); | |
controller = new AbortController(); | |
} | |
} | |
document.querySelector('#abort').onclick = async (e) => { | |
controller.abort(); | |
document.querySelector('#result').innerText = '中止しました'; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment