【问题标题】:Opera won't recognize iframe.loadOpera 无法识别 iframe.load
【发布时间】:2011-09-30 18:40:52
【问题描述】:

我有一个正在通过 iframe 上传的文件。我现在可以在除 Opera 之外的所有浏览器中使用它。要首先提交表单,我有

$(document).ajaxComplete(function() {
    $('.aboutContentImageForm').each(function() {
        var $this = $(this);
        $this.find('[type=file]').change(function() {
            $this.submit();
        });
    });
});

然后为了捕获返回的帖子数据,我使用

$('.aboutContentImageForm').live('submit', function() {     
    $('#' + $this.attr('target')).load(function() {
        
        var responseHtml = $(this).contents().find('body'),
        response = responseHtml.html();

        alert(response);
    });
});

还有我的 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>

所以我的表单以 iframe 为目标,然后在 iframe 完成加载后,抓取返回的数据。

我可以确认 iframe 正在获取响应数据。点击提交后,我可以在框架中看到它。我只是无法捕获 iframe 接收所述数据的事件。这是.load() 的错误吗?

编辑

load() 中添加alert 后,它看起来确实识别出此操作已完成,但他们为什么无法获得我的响应数据?

【问题讨论】:

  • 看到有这个问题的完整页面真的很有趣:-o

标签: jquery browser iframe load opera


【解决方案1】:

我认为您的方法是正确的,但是用户代理之间的 iFrame 中的 DOM 准备情况存在不一致。 jQuery 的表单插件使用了同样的技术。查看该插件的源代码,我可以看到他们不得不花一些时间来处理这个问题,并且特别提到了 Opera。

您可能想看看那里的一些想法:https://github.com/malsup/form/blob/e77e287c8024d200909a7b4f4a1224503814e660/jquery.form.js#L409

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多