我需要获得ajax请求的%完成率.
我尝试了以下方法:
$(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);
});
});
问题是我如何检查上面的代码是否有效.我总是进入100firebug控制台,我怀疑而不是在控制台中100应该有多个%条目.
my_path是一个从MySQL DB返回记录的PHP页面.有没有办法减慢进程/页面呈现以检查功能?