0

JavaScript dynamic data loading progress bar

i tried some of the codes found here but i am not able to get result

    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  
    } 

i should get the percent load in console, but i am not able to get it

caitriona
  • 8,569
  • 4
  • 32
  • 36

1 Answers1

0

Try this

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

and/or

 req.open("GET", "http://stackoverflow.com/questions/3790471/xmlhttprequest-js-image-loading", false);  
Ashwin Singh
  • 7,197
  • 4
  • 36
  • 55
  • Even that was not able get the progress. The problem is that when i run that script i should get some thing like 10%,55% but it just simply shows 100% its running after loading the page –  Jul 13 '12 at 05:01
  • http://jsfiddle.net/kanishkablack/VXmDZ/20/ i have added some code here could u check it once –  Jul 13 '12 at 05:08
  • if its too fast i think there should be a way to refresh the function at 100 milliseconds –  Jul 13 '12 at 05:13