33 lines
860 B
JavaScript
33 lines
860 B
JavaScript
|
|
document.addEventListener("DOMContentLoaded", function() {
|
||
|
|
console.log("zaladowano...")
|
||
|
|
|
||
|
|
function getData() {
|
||
|
|
return fetch('./php/get.php')
|
||
|
|
.then(res => {
|
||
|
|
console.log("Res:", res)
|
||
|
|
return res.json()
|
||
|
|
})
|
||
|
|
.then(data => {
|
||
|
|
console.log("Data:", data)
|
||
|
|
renderTable(data)
|
||
|
|
})
|
||
|
|
.catch(error => {
|
||
|
|
console.log("Error:", error)
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
function renderTable(data) {
|
||
|
|
let table = document.getElementById('tab')
|
||
|
|
data.forEach(row => {
|
||
|
|
let tr = document.createElement('tr');
|
||
|
|
tr.innerHTML=
|
||
|
|
`<td>${row.nazwa}</td>
|
||
|
|
<td>${row.czas_trwania}</td>
|
||
|
|
<td>${row.cena}</td>`
|
||
|
|
|
||
|
|
table.appendChild(tr)
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
getData()
|
||
|
|
})
|