1

Problem: I need to upload several different files at once. When the files are uploaded to the server, they are imported into the database. When all the files have been uploaded & imported, I need to call a final database procedure which proccesses the imports.

$("#igUpload1").on("iguploadfileuploaded", function (e, ui) {                            
    fileCounter++;

    // calling webmethod to process the file on server side
    $.ajax({
          type: 'POST',
          url: '<%= HttpContext.Current.Request.Url.AbsoluteUri + "/processFile" %>',
          data: '{ fileName: "' + ui.filePath + '"}',
          contentType: 'application/json; charset=utf-8',
          dataType: 'json',
          success: function (msg) {
             log(msg.d);
             // When the last file has been proccessed, I need to call another webmethod!
          }
    });

});

My first approach was to compare the fileCounter to the number of files to be uploaded, and when the last file has been uploaded and imported, I would call the final import method. This unfortunately doesn't work, as it's possible that the last file is imported faster than one of the earlier files.

Also, the number of files that will be uploaded can vary.

How do I do this? Is an jquery queue, or maybe deferred, a possible solution?

user66875
  • 2,772
  • 3
  • 29
  • 55
  • 1
    You can use sequencing. described below: http://stackoverflow.com/questions/3034874/sequencing-ajax-requests – Aman Jun 08 '15 at 09:19
  • 1
    I've used the file count method for parallel asychronous file transfers. It works well, but you need to located your fileCounter inside the success function. The way you have it coded will increment when the transfer starts rather than when it completes. – Yogi Jun 08 '15 at 09:26

0 Answers0