I am trying to show a progress bar before navigating from one page to another within the same website.
My function binds an updateProgress function to XMLHttpRequest onprogress event and it redirects user to a new page on (xhr.readyState == 4 && xhr.status == 200) It seems working fine except that Chrome shows "total" as zero which won't let the progress bar function properly. My code is below.
Thank you in advance...
$('.ajaxNavi').click(function (e) {
e.preventDefault();
var url = $(this).attr('href');
var xhr = new XMLHttpRequest();
xhr.onprogress = updateProgress;
xhr.onreadystatechange = function () {
if (xhr.readyState == 4 && xhr.status == 200)
// REDIRECT HERE
}
});
xhr.open("GET", url, true);
xhr.setRequestHeader("Content-Type", "text/html");
xhr.send();
});
function updateProgress(e) {
console.log(e.loaded + ' ' + e.total);
}