From 6b0db50680a52e4ca7e6d0ee8ed3dae6a1093d16 Mon Sep 17 00:00:00 2001 From: xengineering Date: Sun, 3 Mar 2024 14:16:20 +0100 Subject: view: Provide JS function to delete a recipe --- view/static/ceres.js | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/view/static/ceres.js b/view/static/ceres.js index acb52a4..a6b5591 100644 --- a/view/static/ceres.js +++ b/view/static/ceres.js @@ -1,9 +1,9 @@ var forms = document.querySelectorAll('form'); forms.forEach(form => { - form.addEventListener('submit', sendFormAsJson); + form.addEventListener('submit', updateFormData); }); -function sendFormAsJson(event) { +function updateFormData(event) { event.preventDefault(); const form = event.target; @@ -30,3 +30,20 @@ function sendFormAsJson(event) { console.error('Network error:', error); }); } + +function del(url) { + fetch(url, {method: 'DELETE'}) + .then(response => { + if (response.ok) { + console.log('Deletion successfully'); + } else { + console.error('Deletion failed'); + } + if (response.redirected) { + window.location.href = response.url; + } + }) + .catch(error => { + console.error('Network error:', error); + }); +} -- cgit v1.2.3-70-g09d2