Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- async function DELETE(url) {
- const OK = 200;
- let response = await fetch(url, {
- method: "DELETE",
- });
- if (response.status !== OK)
- throw new Error("DELETE status code " + response.status);
- return await response.json();
- }
- function main() {
- let rows = document.querySelectorAll('tr');
- for (let row of rows) {
- row.addEventListener('click', async function() {
- let res = await DELETE('/' + row.id);
- console.log("Status: " + res.ok)
- row.style.backgroundColor = "red";
- })
- }
- };
- /*
- function main() {
- let rows = document.querySelectorAll('tr');
- for (let row of rows) {
- row.addEventListener('click', async function() {
- let res = await DELETE('/' + row.cells[0].innerHTML);
- console.log("Status: " + res.ok)
- row.style.backgroundColor = "red";
- })
- }
- };
- */
- main();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement