diff --git a/index.html b/index.html index 9d6f2e1..7c4acac 100644 --- a/index.html +++ b/index.html @@ -13,7 +13,7 @@ -
+

\ No newline at end of file diff --git a/script.js b/script.js index 11600e2..33e69d0 100644 --- a/script.js +++ b/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 = ''; + + // Aggiungiamo ogni pizza come riga della tabella + pizze.pizze.forEach(pizza => { + table += ` + + + + `; + }); + + table += '
IDNomePrezzo
${pizza.id}${pizza.nome}${pizza.prezzo}€
'; + + // 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."); + }); +} \ No newline at end of file