HTML5 file uploading with multiple progress bars

前端 未结 2 1807
孤城傲影
孤城傲影 2020-12-25 08:49

I\'m uploading multiple files via XmlHTTPRequest and HTML5. I have the uploading working fine, but I would like to have a progress bar for each file upload going on. The c

2条回答
  •  感情败类
    2020-12-25 09:21

    Your example doesn't work properly becourse you don't take into account that xhr progress event is fired when all list items had been already created. However there are a lot of ways to make your example work. The idea is to let xhr know what exactly list item it is dealing with. For example use this code (I didn't check if it works. The purpose of this code is to describe the idea):

    var xhr = new XMLHttpRequest();
    xhr.upload.li = li;
    xhr.upload.addEventListener('progress', function(e) {
        var percent = parseInt(e.loaded / e.total * 100);
        this.li.find(".progressbar").width(percent);
    }, false);
    

提交回复
热议问题