JSFiddle - React, Tailwind, and code Playground
HTML
<div id="stats" style="color:blue"></div>
JavaScript
var getJSON = function (url) {
"use strict";
return new Promise(function(resolve, reject) {
var xhr = new XMLHttpRequest();
xhr.open('get', url, true);
xhr.responseType = 'json';
xhr.onload = function() {
var status = xhr.status;
if (status == 200) {
resolve(xhr.response);
} else {
reject(status);
}
};
xhr.send();
});
};
function updateCount() {
"use strict";
getJSON('http://192.99.124.166:8080/count').then(function(data) {
console.log('update');
stats.innerText = data.result; //display the result in an HTML element
});
}
updateCount();
setInterval(updateCount, 10000);