I'm implementing a workaround for the 'can't upload files using AJAX' problem (in short, the form targets an iframe, and I want jQuery to then grab the content of the iframe and process it).
At the moment, I have a submit handler which is called whenever any form is submitted. It determines whether there is a file upload field in the form, and if there is, it unbinds itself and calls submit(). Unfortunately, submit() is not actually triggered until AFTER the custom handler has return'd false. Thus:
$('form').livequery('submit.custom', function() {
if ($(this).has('input[type=file]').length != 0) {
$(this).unbind('submit.custom');
$('body').append('<div id="file_iframe"></div>');
$('#file_iframe').append('<iframe name="postframe" id="postframe" class="hidden" src="" />');
$(this).attr("target", "postframe");
$(this).submit(); // <-- Doesn't trigger until after 'return false;'
}
return false;
});
This means that I can't process the data in the iframe. Instead, I was thinking of binding a new custom handler within the current custom handler (confused yet?), which would then (presumably) be what was triggered after the current handler returns false - but I would need that new handler to trigger the default submit action before then continuing to process. Is there any way of doing this, or some other way around the problem that you can think of?
$('form').submit(function() {
// Do something to trigger default action, ie actually post the form
// Then do some other bits and pieces
});
I'd be grateful for any help!