Implementazione funzione lista pizze

This commit is contained in:
Andrea
2025-11-06 09:26:45 +01:00
parent 38dbb20061
commit 74aeca8bbd
2 changed files with 34 additions and 1 deletions

View File

@@ -13,7 +13,7 @@
<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> <button onclick="location.href='delete.html'">Elimina</button>
<br> <br><br>
<div id="tabellaPizze"></div> <div id="tabellaPizze"></div>
</body> </body>
</html> </html>

View File

@@ -12,3 +12,36 @@ function orkodyo(){
.then((result) => alert(result)) .then((result) => alert(result))
.catch((error) => console.error(error)); .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.");
});
}