adejs/static/js/totalTable.js

39 lines
1002 B
JavaScript
Raw Normal View History

let loadingDiv = document.getElementById('loading');
2017-09-25 17:17:24 +02:00
let errorDiv = document.getElementById('error');
let resultDiv = document.getElementById('result');
2017-09-25 17:17:24 +02:00
const timeout = 10000;
function getTable() {
// Send XHR to totalTable
2017-09-25 17:17:24 +02:00
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";
2017-09-25 17:17:24 +02:00
errorDiv.style.display = "none";
resultDiv.innerHTML = text;
}
function setError() {
loadingDiv.style.display = "none";
2017-09-25 17:17:24 +02:00
errorDiv.style.display = "";
}
2017-09-25 17:17:24 +02:00
document.getElementById('tryAgain').addEventListener('click', getTable);
getTable();