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