Added delete button for each pizza
This commit is contained in:
@@ -10,7 +10,6 @@
|
|||||||
<button onclick="listPizze()">Lista</button>
|
<button onclick="listPizze()">Lista</button>
|
||||||
<button onclick="location.href='add.html'">Aggiungi</button>
|
<button onclick="location.href='add.html'">Aggiungi</button>
|
||||||
<button onclick="location.href='edit.html'">Modifica prezzo</button>
|
<button onclick="location.href='edit.html'">Modifica prezzo</button>
|
||||||
<button onclick="location.href='delete.html'">Elimina</button>
|
|
||||||
|
|
||||||
<br><br>
|
<br><br>
|
||||||
<div id="tabellaPizze"></div>
|
<div id="tabellaPizze"></div>
|
||||||
|
|||||||
20
script.js
20
script.js
@@ -24,7 +24,7 @@ function listPizze(){
|
|||||||
.then((response) => response.json())
|
.then((response) => response.json())
|
||||||
.then((pizze) => {
|
.then((pizze) => {
|
||||||
// Creiamo la tabella
|
// Creiamo la tabella
|
||||||
let table = '<table border="1"><tr><th>ID</th><th>Nome</th><th>Prezzo</th></tr>';
|
let table = '<table border="1"><tr><th>ID</th><th>Nome</th><th>Prezzo</th><th>Azioni</th></tr>';
|
||||||
|
|
||||||
// Aggiungiamo ogni pizza come riga della tabella
|
// Aggiungiamo ogni pizza come riga della tabella
|
||||||
pizze.pizze.forEach(pizza => {
|
pizze.pizze.forEach(pizza => {
|
||||||
@@ -32,6 +32,7 @@ function listPizze(){
|
|||||||
<td>${pizza.id}</td>
|
<td>${pizza.id}</td>
|
||||||
<td>${pizza.nome}</td>
|
<td>${pizza.nome}</td>
|
||||||
<td>${pizza.prezzo}€</td>
|
<td>${pizza.prezzo}€</td>
|
||||||
|
<td><button onclick="deletePizza({pizza.id})">Elimina</button></td>
|
||||||
</tr>`;
|
</tr>`;
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -42,6 +43,21 @@ function listPizze(){
|
|||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
console.error(error)
|
console.error(error)
|
||||||
alert("Errore nel recupero delle pizze, controllare la console per i dettagli.");
|
alert("Errore nel recupero delle pizze, controllare la console per dettagli sull'errore.");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function deletePizza(id){
|
||||||
|
const requestOptions = {
|
||||||
|
method: "DELETE",
|
||||||
|
redirect: "follow"
|
||||||
|
};
|
||||||
|
|
||||||
|
fetch("http://localhost:5011/api/pizze/1", requestOptions)
|
||||||
|
.then((response) => response.text())
|
||||||
|
.then((result) => alert("Pizza eliminata con successo!"))
|
||||||
|
.catch((error) => {
|
||||||
|
console.error(error)
|
||||||
|
alert("Errore nell'eliminazione della pizza, controllare la console per dettagli sull'errore.");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user