Advertisement
Guest User

Untitled

a guest
Jan 21st, 2020
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  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();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement