Currently, I have a JavaScript function that refreshes a specific section of a Rails-generated view every 2.5 seconds using a JS request to update a basic progress bar.
function refreshPage(){
$.ajax({
type:"GET",
dataType:"script"
})
}
setInterval(function(){
refreshPage();
}, 2500);
However, the refreshing process continues even after the user has navigated away from the page. This issue persists in both Development and Production environments. The only solution is for the user to visit another page and manually refresh by pressing F5.
I suspect there may be a simple solution that I am overlooking. Should I implement a method to determine when the progress bar is complete so that I can stop sending JS requests?