0

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  
    } 

我应该在控制台中获得百分比负载,但我无法获得它

4

1 回答 1

0

尝试这个

req.addEventListener("progress", onUpdateProgress, false);  

和/或

 req.open("GET", "http://stackoverflow.com/questions/3790471/xmlhttprequest-js-image-loading", false);  
于 2012-07-13T04:56:44.830 回答