JavaScript动态数据加载进度条
我尝试了一些在这里找到的代码,但我无法得到结果
var req = new XMLHttpRequest();
req.addEventListener("progress", onUpdateProgress);
req.addEventListener("load", onTransferComplete);
req.addEventListener("error", onTransferFailed);
req.addEventListener("abort", onTransferFailed);
req.open("GET", "http://stackoverflow.com/questions/3790471/xmlhttprequest-js-image-loading");
req.send();
function onUpdateProgress(e) {
var percent_complete = e.loaded/e.total;
console.log(percent_complete);
}
function onTransferFailed(e) {
alert("Something went wrong. Please try again.");
}
function onTransferComplete(e) {
//Problem
}
我应该在控制台中获得百分比负载,但我无法得到它
答案 0 :(得分:0)
试试这个
req.addEventListener("progress", onUpdateProgress, false);
和/或
req.open("GET", "http://stackoverflow.com/questions/3790471/xmlhttprequest-js-image-loading", false);