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?