Progress bar while uploading large files with XMLHttpRequest

后端 未结 2 1572
孤独总比滥情好
孤独总比滥情好 2020-12-14 20:31

I am trying to upload some large files to the server using XMLHttpRequest and file.slice.
I\'ve manage doing this with the help of documentations and other various li

2条回答
  •  南笙
    南笙 (楼主)
    2020-12-14 20:50

    As stated in https://stackoverflow.com/a/3694435/460368, you could do :

    if(xhr.upload)
         xhr.upload.onprogress=upload.updateProgress;
    

    and

    updateProgress: function updateProgress(evt) 
    {
       if (evt.lengthComputable) {
           var progress = Math.ceil(((upload.loaded + evt.loaded) / upload.total) * 100);
           $("#dvProgressPrcent").html(progress + "%");
           $get('dvProgress').style.width = progress + '%';
       }
    }
    

提交回复
热议问题