I am attempting to use the setInterval function to fetch data from another website every 10 seconds. However, it is only running for the first time and then stopping.
setInterval(fetchData("testtest"), 10000);
function fetchData(username){
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (xhttp.readyState == 4 && xhttp.status == 200) {
document.getElementById("demo").innerHTML = xhttp.responseText;
var jsonData= JSON.parse(xhttp.responseText);
console.log(jsonData.total);
console.log(username);
}
};
var url="https://hypothes.is/api/search?user=" + username + "&sort=created&order=asc";
xhttp.open("GET", url, true);
xhttp.send();
alert("test");
}