Aggiunta controllo prompt modifica (non richiedere motifica a prompt vuoto o annullato)
This commit is contained in:
44
script.js
44
script.js
@@ -56,28 +56,30 @@ function deletePizza(id){
|
|||||||
function editPizza(id){
|
function editPizza(id){
|
||||||
let prezzo = prompt("Inserire prezzo da assegnare");
|
let prezzo = prompt("Inserire prezzo da assegnare");
|
||||||
|
|
||||||
const myHeaders = new Headers();
|
if (prezzo){
|
||||||
myHeaders.append("Content-Type", "application/json");
|
const myHeaders = new Headers();
|
||||||
|
myHeaders.append("Content-Type", "application/json");
|
||||||
|
|
||||||
const raw = JSON.stringify({
|
const raw = JSON.stringify({
|
||||||
"prezzo": prezzo
|
"prezzo": prezzo
|
||||||
});
|
});
|
||||||
|
|
||||||
const requestOptions = {
|
const requestOptions = {
|
||||||
method: "PUT",
|
method: "PUT",
|
||||||
headers: myHeaders,
|
headers: myHeaders,
|
||||||
body: raw,
|
body: raw,
|
||||||
redirect: "follow"
|
redirect: "follow"
|
||||||
};
|
};
|
||||||
|
|
||||||
fetch(apiUrl + "/api/pizze/" + id, requestOptions)
|
fetch(apiUrl + "/api/pizze/" + id, requestOptions)
|
||||||
.then((response) => response.text())
|
.then((response) => response.text())
|
||||||
.then((result) => {
|
.then((result) => {
|
||||||
alert("Pizza modificata con successo!");
|
alert("Pizza modificata con successo!");
|
||||||
listPizze();
|
listPizze();
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
console.error(error)
|
console.error(error)
|
||||||
alert("Errore nella modifica, controllare la console per dettagli sull'errore.");
|
alert("Errore nella modifica, controllare la console per dettagli sull'errore.");
|
||||||
});
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user