This repository has been archived on 2023-01-06. You can view files and clone it, but cannot push or open issues or pull requests.
web/app/view/pages/race/live-results.php
2022-04-08 12:24:16 +00:00

67 lines
1.1 KiB
PHP

<h1>Live resultater</h1>
<br>
<noscript>
Denne siden krever JavaScript
</noscript>
<div id="ranking-table">
Laster inn...
</div>
<script>
var hash = 0;
document.addEventListener('DOMContentLoaded', function() {
loop();
});
async function loop()
{
try {
await updateTable();
} catch (error) {
console.log(error);
}
setTimeout(function() {
loop();
}, 1000);
}
async function updateTable()
{
let response = await fetch("sync.php?h=" + hash);
if (response.status === 204)
{
return;
}
let json = await response.json();
hash = json.hash;
let data = json.data;
let table_html = "";
table_html += "<table>";
table_html += "<tr>";
table_html += "<th>Navn</th>";
table_html += "<th>Bestetid</th>";
table_html += "</tr>";
data.forEach(element => {
table_html += "<tr>";
table_html += "<td>" + element.n + "</td>";
table_html += "<td>" + element.d + "</td>";
table_html += "</tr>";
});
table_html += "<table>";
console.log(data);
document.getElementById("ranking-table").innerHTML = table_html;
}
</script>