From bfb339f466fae5b7156393d56421075a5bc0658c Mon Sep 17 00:00:00 2001 From: Andrea Date: Wed, 12 Nov 2025 08:48:06 +0100 Subject: [PATCH] Aggiunta controllo prompt modifica (non richiedere motifica a prompt vuoto o annullato) --- script.js | 44 +++++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/script.js b/script.js index 5e56d1e..ad8c812 100644 --- a/script.js +++ b/script.js @@ -56,28 +56,30 @@ function deletePizza(id){ function editPizza(id){ let prezzo = prompt("Inserire prezzo da assegnare"); - const myHeaders = new Headers(); - myHeaders.append("Content-Type", "application/json"); + if (prezzo){ + const myHeaders = new Headers(); + myHeaders.append("Content-Type", "application/json"); - const raw = JSON.stringify({ - "prezzo": prezzo - }); + const raw = JSON.stringify({ + "prezzo": prezzo + }); - const requestOptions = { - method: "PUT", - headers: myHeaders, - body: raw, - redirect: "follow" - }; + const requestOptions = { + method: "PUT", + headers: myHeaders, + body: raw, + redirect: "follow" + }; - fetch(apiUrl + "/api/pizze/" + id, requestOptions) - .then((response) => response.text()) - .then((result) => { - alert("Pizza modificata con successo!"); - listPizze(); - }) - .catch((error) => { - console.error(error) - alert("Errore nella modifica, controllare la console per dettagli sull'errore."); - }); + fetch(apiUrl + "/api/pizze/" + id, requestOptions) + .then((response) => response.text()) + .then((result) => { + alert("Pizza modificata con successo!"); + listPizze(); + }) + .catch((error) => { + console.error(error) + alert("Errore nella modifica, controllare la console per dettagli sull'errore."); + }); + } } \ No newline at end of file