I have a file that's being upload via iframe work around. I have it working in all browsers except Opera now. To first submit th开发者_StackOverflow社区e form, I have
$(document).ajaxComplete(function() {
$('.aboutContentImageForm').each(function() {
var $this = $(this);
$this.find('[type=file]').change(function() {
$this.submit();
});
});
});
Then to capture the post data returned, I use
$('.aboutContentImageForm').live('submit', function() {
$('#' + $this.attr('target')).load(function() {
var responseHtml = $(this).contents().find('body'),
response = responseHtml.html();
alert(response);
});
});
And my HTML
<form action="ajax/about_content.php" method="post" enctype="multipart/form-data" class="aboutContentImageForm" target="form_image_upload_content_id_8">
<fieldset>
<input type="file" name="image_path" id="image_path_8">
</fieldset>
</form>
<iframe id="form_image_upload_content_id_8" name="form_image_upload_content_id_8"></iframe>
So my form targets the iframe, and then once the iframe is finished loading, grab the data returned.
I can confirm the iframe is getting the response data. I can see it in the frame after I hit submit. I just can't capture the event of the iframe receiving said data. Is this a bug with .load()
?
Edit
after putting an alert
within the load()
it looks like it DOES recognize that this action is completed, but they why can't I get my response data?
I think you've got the right approach, but there are inconsistencies with DOM readiness in iFrames between user agents. jQuery's form plugin uses this same technique. Looking at the source code of that plugin, I can see they're having to do some dancing around to deal with this issue, and Opera is specifically mentioned.
You might want to take a look there for some ideas: https://github.com/malsup/form/blob/e77e287c8024d200909a7b4f4a1224503814e660/jquery.form.js#L409
精彩评论