Added begining of XHR way of doing stuff (#3)
This commit is contained in:
33
static/js/totalTable.js
Normal file
33
static/js/totalTable.js
Normal 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();
|
||||
Reference in New Issue
Block a user