Implementazione funzione lista pizze
This commit is contained in:
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