I am using the Plupload file downloader in the form. I want to configure it so that when I submit the form, that is, when the "Submit" button is clicked, the first thing that happens is the file upload, followed by the submission of the form.
From what I can say, and I could be wrong in that, but it seems that calling uploader.start() is an asynchronous function call. So, at this point, the download will begin, and the form will be submitted before the files are downloaded. The problem is that I do not control this function call.
I recently read about the new version of jQuery 1.5 and the new Delayed Object , and it looks like this can help me solve this problem. Is there a way to wait for the asynchronous function call to complete its work, and then continue to execute the code after the call. So I'm looking for something like the following pseudo code ...
var uploader = $('#plupload_container').pluploadQueue(); $('#submitButton').click(function() {
Is there a way to βwaitβ for uploader.start() to complete, essentially pause the click event handler so that all files can be loaded first, and then the rest of the click event handler can finish executing? I tried the following, but the "done" is printed before the files are downloaded ...
$.when(uploader.start()).then(function () { console.log("done") });
Another useful information ... I can associate certain events with this instance of the uploader object, for example, "UploadProgress" or "UploadComplete". Can I use the Pending Object anyway to catch when the "UploadComplete" event fires, for example? Is there an AJAX-y way to do this?
Thanks.
source share