diff options
author | xengineering <me@xengineering.eu> | 2024-03-03 14:16:20 +0100 |
---|---|---|
committer | xengineering <me@xengineering.eu> | 2024-03-03 14:16:20 +0100 |
commit | 6b0db50680a52e4ca7e6d0ee8ed3dae6a1093d16 (patch) | |
tree | be114538dabf6b2b63c73524704e45249a603ec3 | |
parent | 7cecddd5ecd95c8d559208f9292a3590f8c4cb37 (diff) | |
download | ceres-6b0db50680a52e4ca7e6d0ee8ed3dae6a1093d16.tar ceres-6b0db50680a52e4ca7e6d0ee8ed3dae6a1093d16.tar.zst ceres-6b0db50680a52e4ca7e6d0ee8ed3dae6a1093d16.zip |
view: Provide JS function to delete a recipe
-rw-r--r-- | view/static/ceres.js | 21 |
1 files 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); + }); +} |