SHARE
TWEET

Untitled

a guest Jan 21st, 2020 80 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. async function DELETE(url) {
  2.     const OK = 200;
  3.     let response = await fetch(url, {
  4.         method: "DELETE",
  5.     });
  6.     if (response.status !== OK)
  7.         throw new Error("DELETE status code " + response.status);
  8.     return await response.json();
  9. }
  10.  
  11. function main() {
  12.     let rows = document.querySelectorAll('tr');
  13.     for (let row of rows) {
  14.         row.addEventListener('click', async function() {
  15.             let res = await DELETE('/' + row.id);
  16.             console.log("Status: " + res.ok)
  17.             row.style.backgroundColor = "red";
  18.         })
  19.     }
  20. };
  21.  
  22. /*
  23. function main() {
  24.     let rows = document.querySelectorAll('tr');
  25.     for (let row of rows) {
  26.         row.addEventListener('click', async function() {
  27.             let res = await DELETE('/' + row.cells[0].innerHTML);
  28.             console.log("Status: " + res.ok)
  29.             row.style.backgroundColor = "red";
  30.         })
  31.     }
  32. };
  33.  */
  34.  
  35. main();
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top