Added begining of XHR way of doing stuff (#3)

This commit is contained in:
Thomas Forgione
2017-09-25 15:26:06 +02:00
parent b893d8933c
commit 5e63027352
5 changed files with 82 additions and 28 deletions

33
static/js/totalTable.js Normal file
View File

@@ -0,0 +1,33 @@
let loadingDiv = document.getElementById('loading');
let resultDiv = document.getElementById('result');
const timeout = 30000;
function getTable() {
// Send XHR to totalTable
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();
window.xhr = xhr;
}
function setData(text) {
loadingDiv.style.display = "none";
resultDiv.innerHTML = text;
}
function setError() {
loadingDiv.style.display = "none";
resultDiv.innerHTML = "An error occured";
}
getTable();