Aggiunta funzione add (sperando che funzioni)
This commit is contained in:
29
script.js
29
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.");
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user