const params = new URLSearchParams(window.location.search); const id = params.get('routecode'); const num = params.get('routenum'); const codiceSpan = document.getElementById('codice-span'); const destSpan = document.getElementById('destinazione-span'); const pNav = document.getElementById('percorso-nav'); //Displays route code codiceSpan.textContent = id; //Nav per tornare indietro pNav.innerHTML = ` `; const urlBackend = `https://setaapi.serverissimo.freeddns.org/routestops/${id}`; //const urlBackend = `http://localhost:5001/arrivals/${codice}`; function caricadati(){ var item=[]; fetch(urlBackend) .then(response => { if (!response.ok) throw new Error("Errore di risposta nel caricamento dei dati, probabilmente il server API รจ offline."); return response.json(); }) .then(data => { item = data; }) .then(data => { const container = document.getElementById('tabella-container'); container.innerHTML = ''; // Creo tabella const table = document.createElement('table'); // Intestazione const thead = document.createElement('thead'); thead.innerHTML = ` Nome: Codice: `; table.appendChild(thead); // Corpo tabella const tbody = document.createElement('tbody'); item.forEach(item => { const element = item; var tr = document.createElement('tr'); tr.innerHTML = ` ${item.desc} ${item.code} `; tbody.appendChild(tr); if(element.islast==true){ destSpan.innerHTML=element.desc.toUpperCase(); } }); table.appendChild(tbody); container.appendChild(table); }) .catch(err => { if(item.error=="Percorso non trovato"){ document.getElementById('tabella-container').textContent = "Percorso non trovato."; }else{ console.error('Errore nel caricamento dati:', err); document.getElementById('tabella-container').textContent = "Errore nella sintassi dei dati ricevuti."; } }); } caricadati();