Implementazione funzione lista pizze
This commit is contained in:
@@ -13,7 +13,7 @@
|
||||
<button onclick="location.href='edit.html'">Modifica prezzo</button>
|
||||
<button onclick="location.href='delete.html'">Elimina</button>
|
||||
|
||||
<br>
|
||||
<br><br>
|
||||
<div id="tabellaPizze"></div>
|
||||
</body>
|
||||
</html>
|
||||
33
script.js
33
script.js
@@ -12,3 +12,36 @@ function orkodyo(){
|
||||
.then((result) => alert(result))
|
||||
.catch((error) => console.error(error));
|
||||
}
|
||||
|
||||
function listPizze(){
|
||||
let reply;
|
||||
const requestOptions = {
|
||||
method: "GET",
|
||||
redirect: "follow"
|
||||
};
|
||||
|
||||
fetch(apiUrl + "/api/pizze", requestOptions)
|
||||
.then((response) => response.json())
|
||||
.then((pizze) => {
|
||||
// Creiamo la tabella
|
||||
let table = '<table border="1"><tr><th>ID</th><th>Nome</th><th>Prezzo</th></tr>';
|
||||
|
||||
// Aggiungiamo ogni pizza come riga della tabella
|
||||
pizze.pizze.forEach(pizza => {
|
||||
table += `<tr>
|
||||
<td>${pizza.id}</td>
|
||||
<td>${pizza.nome}</td>
|
||||
<td>${pizza.prezzo}€</td>
|
||||
</tr>`;
|
||||
});
|
||||
|
||||
table += '</table>';
|
||||
|
||||
// Inseriamo la tabella nel div
|
||||
document.getElementById('tabellaPizze').innerHTML = table;
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error(error)
|
||||
alert("Errore nel recupero delle pizze, controllare la console per i dettagli.");
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user