From 1867b0e7d120d2395bf22480b941ab3506b6b840 Mon Sep 17 00:00:00 2001 From: Andrea Date: Wed, 12 Nov 2025 08:51:58 +0100 Subject: [PATCH] Aggiunta funzione add (sperando che funzioni) --- script.js | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/script.js b/script.js index ad8c812..a264f01 100644 --- a/script.js +++ b/script.js @@ -82,4 +82,33 @@ function editPizza(id){ alert("Errore nella modifica, controllare la console per dettagli sull'errore."); }); } +} + +function addPizza(nome, id, prezzo){ + const myHeaders = new Headers(); + myHeaders.append("Content-Type", "application/json"); + + const raw = JSON.stringify({ + "id": id, + "nome": nome, + "prezzo": prezzo + }); + + const requestOptions = { + method: "POST", + headers: myHeaders, + body: raw, + redirect: "follow" + }; + + fetch(apiUrl + "/api/pizze/" + id, requestOptions) + .then((response) => response.text()) + .then((result) => { + alert("Pizza aggiunta con successo!"); + listPizze(); + }) + .catch((error) => { + console.error(error) + alert("Errore nell'aggiunta, controllare la console per dettagli sull'errore."); + }); } \ No newline at end of file