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 user select multiple file to upload, the cancel button only cancel 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.
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(); }
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.