Dominic
Dominic

Reputation: 1304

Callback for form submission (with jQuery)

I have a modal window that presents a form to users. The form includes one or more file uploads as well. Therefore I cannot submit the form with ajax.

At the moment I'm doing a standard submit with a submit button. When the form is submitted (which takes a few seconds in general), a PDF is generated and sent back for download (i.e. the Content-Disposition: attachment header), to force the download. Once the upload of the form data has completed, I need to close the modal window. If I call the close method straight way the submission never completes and the file download is never triggered (I think this is because the modal window is removed from the DOM). I can set a timeout, but there could be n number of images, so the time it takes to upload is unpredictable (and relative to the number of uploads).

I've looked at the jQuery form plugin (http://jquery.malsup.com/form/#file-upload), but apparently it uses an iframe to upload files, so I'm not sure if it will achieve what I need.

Thanks for any help,

Dom.

Upvotes: 2

Views: 3868

Answers (2)

user24359
user24359

Reputation:

Rewritten after rereading the question. Here's what I'd try:

  1. Serialize the form and make it the return value from the dialog, i.e. pass the data back to the page.
  2. Close the dialog
  3. Submit the serialized form

Upvotes: 0

nickf
nickf

Reputation: 546055

The Form plugin you mentioned should work - why do you suspect it won't?

Upvotes: 1

Related Questions