I'm trying to poll a NodeJs Server using the fetch
function but the setInterval
method is actually not working as expected (it runs only once and then stops).
window.onload = () => {
let label = document.getElementById('button_badge');
setInterval(getNotification(label), 3000);
};
function getNotification(label) {
fetch('/getnotification')
.then(value => {
value.json()
.then(value1 => {
console.log(value1);
label.innerHTML = value1.listWatchers.length;
});
})
.catch(reason => {
console.log(reason)
});
}
The final result (which is value1 in this case) should be used to set a span value (label variable)