Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@goofmint
Created April 9, 2019 05:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save goofmint/5ce5bf07c62c3d6471cb18b78bd2a15d to your computer and use it in GitHub Desktop.
Save goofmint/5ce5bf07c62c3d6471cb18b78bd2a15d to your computer and use it in GitHub Desktop.
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