I need to get the % completion for ajax request.
I tried the following:
$(document).ready(function() {
$.ajax({
xhr : function() {
var xhr = new window.XMLHttpRequest();
xhr.upload.addEventListener("progress", function(evt) {
if (evt.lengthComputable) {
var percentComplete = (evt.loaded / evt.total) * 100;
//Do something with upload progress here
}
}, false);
xhr.addEventListener("progress", function(evt) {
if (evt.lengthComputable) {
var percentComplete = (evt.loaded / evt.total) * 100;
//Do something with download progress
console.log(percentComplete);
}
}, false);
return xhr;
},
url : my_path
}).done(function(data) {
console.log(data);
});
});
The problem is how do I check whether the above code is working or not. I always get 100
in the firebug console, I doubt instead of 100
there should be multiple %
entries in console.
my_path
is a PHP page that returns records from MySQL DB. Is there any way to slow down the process/page rendering to check the functionality?