This is a follow up question from my previous one "How do I measure a loading time of an AJAX request and display a loading panel?". Now I am wondering how will I suppose to display an animated loading bar/panel like this:
And what I mean is that an actual moving panel from 0% to 100%. I have here a bit of code to begin the discussion. I'm implementing a tutorial loading from this wonderful site.
$("#connection").click(function(e) {
e.preventDefault();
//show_loading();
$.ajax({
url: "./home/connect",
type: 'GET',
dataType: 'json',
progress: function(jqXHR, progressEvent) {
if (progressEvent.lengthComputable) {
console.log("Loaded " + (Math.round(progressEvent.loaded / progressEvent.total * 100)) + "%");
} else {
console.log("Loading...");
}
},
success : function(data) {
//hide_loading();
Materialize.toast(data.db_connect, 4000, 'rounded green');
},
});
});
The problem with this code is that it displays 100% in the console the moment it reaches to 100% and not live ( showing the actual counting from 0 - 100 ).