[jQuery] Accessing an iframe after fileupload
I am having the devil’s own business trying to access the contents of an iframe which is used as a target for a file upload.
In a php file called AJAXaddFile.php, I have the form etc - as you can see it handles the return itself:
<form action="<?php echo $_SERVER['PHP_SELF'] . '?' . $_SERVER['QUERY_STRING'] ?>" id="AJAXaddFile" method="post" enctype="multipart/form-data" target="form_iframe">
....
<input type="submit" value="Upload file" name="submit" id="aafSubmit" style="background-color:#2C5E9B; color:#FFFFFF;" />
Then outside the form is the actual iframe itself:
<iframe name="form_iframe" id="form_iframe" src="../templates/blank.html" class="loader" style="display:none"></iframe>
Blank.html is exactly that – just an empty page with no mark up at all.
The fileupload works just fine, but what I want to do refresh the screen once the file has been uploaded. My plan had been to grab the contents of the iFrame and then using a $().html function dynamically refresh the screen showing the newly uploaded file.
Playing around with CSS off I can see the iFrame contains the returned data with the recently uploaded file as the top of the list which is exactly what I want. But try as I might I can’t seem to access that wretched iFrame through jQuery.
The jQuery is hanging off a submit function:
$('#AJAXaddFile').submit(function() {
}
I have tried all manner of ways of getting hold of that content. If I do $('#form_iframe').html() after the .submit call I simply get the contents of blank.html back again. I tried doing an Ajax call using .get on the original file as part of the submit callback, but it seems to access the data *before* the upload has taken place, not after the sumbit has happened. If I try and grab the iframe outside of the .submit call then obviously it doesn't contain the data.
What I am trying to do is to grab the data once the server has returned the data (I tried a .ready on the iFrame but it picks it up before the php script has fired).
Alas I can't point to this in real life as it is on a development server which is not visible.
I suspect that is as clear as mud – but if anyone can pick their way through this and has any pointers ... I would be soooo appreciative.
Many many thanks
Ben
No virus found in this outgoing message.
Checked by AVG.
Version: 7.5.524 / Virus Database: 269.23.10/1421 - Release Date: 07/05/2008 17:23