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

1 Answer 1

0

Try this

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

and/or

 req.open("GET", "http://stackoverflow.com/questions/3790471/xmlhttprequest-js-image-loading", false);  
Sign up to request clarification or add additional context in comments.

3 Comments

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
jsfiddle.net/kanishkablack/VXmDZ/20 i have added some code here could u check it once
if its too fast i think there should be a way to refresh the function at 100 milliseconds

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.