0
votes

I've been having problems with blueimp processalways.My code is :

    <script>
       $(function () {
       var uploadButton = $('<button/>').addClass('btn btn-primary').prop('disabled',true).text('Processing...').on('click', function () {
var $this = $(this),data = $this.data();
$this.off('click').text('Abort').on('click', function () {
  $this.remove();
  data.abort();
});
console.log("data = ",data);
data.submit().always(function () {
  $this.remove();
});
    });$('#fileupload').fileupload({
dataType: 'json',
singleFileUploads: false,
replaceFileInput : false,
add: function (e, data) {
  console.log("#1 fileuploadadd data = ",data);
  data.context = $('<div/>').appendTo('#files');
  $.each(data.files, function (index, file) {
    var node = $('<p/>').append($('<span/>').text(file.name));
    if(!index){   node.append('<br>').append(uploadButton.clone(true).data(data));}
    node.appendTo(data.context);
    console.log("#2 fileuploadadd data = ",data);
  });      
},processalways: function (e, data) {
    console.log("processalways!");
    var index = data.index, file = data.files[index],node = $(data.context.children()[index]);
    if(file.preview) {
      node.prepend('<br>').prepend(file.preview);}
     if(file.error) {
        node.append('<br>').append($('<span class="text-danger"/>').text(file.error));}
      if(index+1 === data.files.length) {             data.context.find('button').text('Upload').prop('disabled',!!data.files.error);}
               },

I cannot understand why processalways is never triggered. I also tried with always instead of process always but there is no difference. When I have it like :

    }).on('fileuploadadd',function (e,data) {
    .......       
 }).on('fileuploadprocessalways', function (e,data) {

it works normally but I cannot understand why. Additionally, could someone give me an example of using blueimp's formData?? Thank you in advance

1

1 Answers

0
votes

I can't give you an example for formData, but for the events.

According to this answer: https://stackoverflow.com/a/20491423

You have to use always if you overwrite the add function. This works for me.