const apiUrl = "http://localhost:5011"; function orkodyo(){ let reply; const requestOptions = { method: "GET", redirect: "follow" }; fetch(apiUrl + "/api/pizze", requestOptions) .then((response) => response.text()) .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 += '
IDNomePrezzoAzioni
${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 dettagli sull'errore."); }); } function deletePizza(id){ const requestOptions = { method: "DELETE", redirect: "follow" }; fetch(apiUrl + "/api/pizze/" + id, 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."); }); listPizze(); }