Aggiunta funzione add (sperando che funzioni)

This commit is contained in:
2025-11-12 08:51:58 +01:00
parent bfb339f466
commit 1867b0e7d1

View File

@@ -83,3 +83,32 @@ function editPizza(id){
});
}
}
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.");
});
}