45 lines
1.3 KiB
JavaScript
45 lines
1.3 KiB
JavaScript
document.addEventListener('DOMContentLoaded', function() {
|
|
console.log("ok");
|
|
|
|
const fetchData = () => {
|
|
return fetch('./php/get.php')
|
|
.then(response => {
|
|
if (!response.ok) {
|
|
throw new Error('Błąd pobierania danych');
|
|
}
|
|
return response.json();
|
|
})
|
|
.then(data => {
|
|
console.log("Dane załadowane:", data);
|
|
renderTable(data); // Wywołaj funkcję renderującą tabelę
|
|
})
|
|
.catch(error => {
|
|
console.error("Błąd:", error);
|
|
});
|
|
};
|
|
|
|
// Funkcja do renderowania danych w tabeli
|
|
const renderTable = (data) => {
|
|
const table = document.getElementById('tab');
|
|
|
|
// Usuń wszystkie rzędy po nagłówku (czyli od drugiego)
|
|
while (table.rows.length > 1) {
|
|
table.deleteRow(1);
|
|
}
|
|
|
|
// Dodaj nowe wiersze dla każdego kursu
|
|
data.forEach(row => {
|
|
const tr = document.createElement('tr');
|
|
tr.innerHTML = `
|
|
<td>${row.kurs}</td>
|
|
<td>${row.czas_trwania}</td>
|
|
<td>${row.cena}</td>
|
|
`;
|
|
table.appendChild(tr);
|
|
});
|
|
};
|
|
|
|
// Uruchom pobieranie danych
|
|
fetchData();
|
|
});
|