Article From:https://segmentfault.com/q/1010000011707420
Question:

Similar to this.

Answer 0:

With XmlHttpRequest, you can get the uploaded data length, and with the total length, you can calculate the upload progress in the programs event

Answer 1:

You can bind the progress event to get the progress of the data transferred when you make an HTTP request from the XMLHttpRequest object

    var request = new XMLHttpRequest();                 
                 request.open("POST", "1.php",true);
                 request.onreadystatechange = function(){                    
                    if(request.readyState==4){                        
                        
                    }
                };
                request.upload.addEventListener('progress',progress, false);            
                 request.send(formData);
                 
                 
         function progress(e){
                if(e.lengthComputable){
                    var percentComplete = Math.round(e.loaded/ e.total * 100 )+"%";
                    //total The total file size loaded is the size of the upload.}}

Similar Posts:

Leave a Reply

Your email address will not be published. Required fields are marked *