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