Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>
  <button id="downloadBtn">Download</button>
  <button id="stopBtn">Stop Download</button>
</body>
</html>
 
document.addEventListener("DOMContentLoaded", ()=>{
  // create an object of AbortController
const controller = new AbortController();
// get the signal property from the controller
const signal = controller.signal;
// Get reference to both the download and the stop button
const downloadBtn = document.getElementById("downloadBtn");
const stopBtn = document.getElementById("stopBtn");
// Add click listeners to both the download and stop buttons
downloadBtn.addEventListener("click", ()=>{
// fetch request
// passing signal as an option
fetch('https://jsonplaceholder.typicode.com/posts', {signal})
  .then(response => response.json())
  .then(json => console.log(json)); 
});
stopBtn.addEventListener("click", ()=>{
  controller.abort()
})
});
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers