最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - jquery file upload cancel all uploads - Stack Overflow

programmeradmin1浏览0评论

I am using jQuery File Upload plugin (/) for image upload for my website.

My code:

$('#fileupload').fileupload({
    url: 'server/index.php',
    dataType: 'json',
    dropZone: $('#dropzone')
}).on('fileuploadadd', function (e, data) {
    jqXHR = data;
});

$('button.cancel').click(function () {
jqXHR.abort();
});

When the user selects multiple files to upload, the cancel button only cancels 1 file upload instate of all files.

How can I have the cancel button to cancel all file uploads (in progress) once clicked?

Thank you.

I am using jQuery File Upload plugin (http://blueimp.github.io/jQuery-File-Upload/) for image upload for my website.

My code:

$('#fileupload').fileupload({
    url: 'server/index.php',
    dataType: 'json',
    dropZone: $('#dropzone')
}).on('fileuploadadd', function (e, data) {
    jqXHR = data;
});

$('button.cancel').click(function () {
jqXHR.abort();
});

When the user selects multiple files to upload, the cancel button only cancels 1 file upload instate of all files.

How can I have the cancel button to cancel all file uploads (in progress) once clicked?

Thank you.

Share Improve this question edited Oct 29, 2021 at 6:48 Ahmet Emre Kilinc 7,00319 gold badges36 silver badges47 bronze badges asked Mar 29, 2014 at 3:08 user1995781user1995781 19.5k45 gold badges139 silver badges242 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 2

extracted from here

$('#fileupload').fileupload({
    add: function(e, data) {
         $('.progress_bar_wrapper').append($('.progress_context:first').clone());
        data.context = $('.progress_context:last');
        data.content.find('.abort').click(abortUpload );
        var xhr = data.submit();
        data.context.data('data',{jqXHR: xhr}); // so much data...
    }
)};

function abortUpload (e) {
     e.preventDefault();
     var template = $(e.currentTarget).closest('.template-upload'),
     data = template.data('data') || {}; // data, data , data (queue Monty Python skit)
      if (!data.jqXHR) {
        data.errorThrown = 'abort';
        this._trigger('fail', e, data);
      } else {
        data.jqXHR.abort();
      }
}

How about using a Stack to keep Track of uploads?

}).on('fileuploadadd', function (e, data) {
    jqXHR.push(data);
});

$('button.cancel').click(function () {
    for (i=0; i < jqXHR.length; i++) { jqXHR[i].abort(); }
});
发布评论

评论列表(0)

  1. 暂无评论