coolhand79
coolhand79

Reputation:

Safari doesn't allow AJAX Requests after form submit?

I am writing a Javascript based upload progress meter. I want to use the standard multipart submit method (rather than submitting the file in an iframe). During the submit, I send ajax requests that return the % complete of the upload and then update the progress meter accordingly.

This all works smoothly in FireFox & IE. However, Safari seems prevent the completion of ajax requests after the main form has been submitted. In the debugger, I can see the request headers, but it appears as though the response is never received.

Anyone aware of this, or how to get around it?

Upvotes: 9

Views: 4798

Answers (4)

Neil
Neil

Reputation: 161

This is a WebKit bug. See https://bugs.webkit.org/show_bug.cgi?id=23933

Upvotes: 3

Poldon
Poldon

Reputation: 365

Yes, this is how Safari and any browser based on WebKit (i.e. Google Chrome) behave. I recently ran into this on a file upload progress meter also. I ended up using the same technique seen at http://drogomir.com/blog/2008/6/30/upload-progress-script-with-safari-support to get the ajax to work. In my case, I didn't want to change the look of my application to the one Drogomir uses, but the technique itself worked. Essentially, the solution is to create a hidden iframe only in Safari that loads jQuery and your AJAX script. Then, the top frame calls a function in that frame on form submit. All other browsers still work the same as before.

Upvotes: 3

Javache
Javache

Reputation: 3468

Are you using an iframe to submit your form to? I'm guessing that once the form is submitted, the page enters a state where no more modifications to the DOM can be made.

Check a tutorial such as this one for more information.

Upvotes: 2

Matt
Matt

Reputation: 2902

This actually sounds like correct behaviour to me - and im surprised that firefox and IE behave otherwise.

It is akin to you attempting to leave a page and the page still interacting with you - sounds naughty!

i can see why this would be of benefit - but I would hope it only the case if you are performing a POST to the uri you are currently accessing, or at worst same-domain.

Upvotes: 0

Related Questions