views:

58

answers:

2

The error is shown only when i add a File input. I get a return of FALSE in the success event. happens only in Opera.

Any idea where could be a problem ?

http://jquery.malsup.com/form/

A: 

i have the same issue

interrobang
A: 

jQuery creates a hidden IFRAME to submit the form into, because this is the only way to handle a file upload in an AJAXy way.

The underlying reason for the problem is that Opera fires onload when an empty iframe is inserted into the document. The jQuery script doesn't expect this initial onload event, thinks submitting the form is done, and concludes that it was not successful. The reason it doesn't happen as easily on http presumably has to do with the timing being different when Opera has to encrypt a file upload payload.

If the same script that inserts the IFRAME also initiates document loading into the IFRAME, other browsers will wait until the loading document finishes loading and only fire one load event. (Or something like that - in this specific case, the script that starts document loading is running from a timeout, so it's not even the same script).

My suggested fix would be to enhance the workaround attempt that already exists for this problem:

if (!isXml && (doc.body == null || doc.body.innerHTML == ''  )) 

and check in this if statement whether the URL of the document inside the IFRAME is still the initial javascript:false :

if (!isXml && (doc.body == null || doc.body.innerHTML == '' || doc.URL=='javascript:false' )) 

This should be enough to make sure jQuery waits until the new document is done loading.

hallvors
(BTW, great if you could push this suggestion upstream to the maintainers of that script..)
hallvors