I have a script to fetch API data and display in span, all works with out any issues but i will like to add auto refresh every 5 sec for span element
const url =
'https://api.helium.io/v1/validators/rewards/sum?min_time=2021-07-01T06:42:57Z'
fetch(url)
.then((response) => {
if (response.ok) {
return response.json();
} else {
throw new Error("network bad");
}
})
.then(function(data) {
const total = data.data.total
displayTotal(total);
console.log(total);
})
.catch((error) => {
console.error("fetch error;", error);
})
function displayTotal(total) {
document.getElementById("total").innerText = total.toLocaleString(2);
}
<span id='total' />