39 lines
1002 B
JavaScript
39 lines
1002 B
JavaScript
let loadingDiv = document.getElementById('loading');
|
|
let errorDiv = document.getElementById('error');
|
|
let resultDiv = document.getElementById('result');
|
|
const timeout = 10000;
|
|
|
|
function getTable() {
|
|
// Send XHR to totalTable
|
|
loadingDiv.style.display = "";
|
|
errorDiv.style.display = "none";
|
|
|
|
let xhr = new XMLHttpRequest();
|
|
xhr.timeout = timeout;
|
|
xhr.onreadystatechange = function() {
|
|
if (xhr.readyState === XMLHttpRequest.DONE) {
|
|
if (xhr.status === 200) {
|
|
setData(xhr.responseText);
|
|
} else {
|
|
setError();
|
|
}
|
|
}
|
|
};
|
|
xhr.open('GET', '/total-table', true);
|
|
xhr.send();
|
|
}
|
|
|
|
function setData(text) {
|
|
loadingDiv.style.display = "none";
|
|
errorDiv.style.display = "none";
|
|
resultDiv.innerHTML = text;
|
|
}
|
|
|
|
function setError() {
|
|
loadingDiv.style.display = "none";
|
|
errorDiv.style.display = "";
|
|
}
|
|
|
|
document.getElementById('tryAgain').addEventListener('click', getTable);
|
|
getTable();
|