【问题标题】:jQuery-File-Upload not firing done callback in Internet Explorer (IE9)jQuery-File-Upload 未在 Internet Explorer (IE9) 中触发完成回调
【发布时间】:2013-10-18 12:15:08
【问题描述】:

我检查了一些关于同一问题的问题 blueimp jquery file upload - "done", "complete" callbacks not working for IE 9 ,但即使将我的 Content-Type 设置为 'text/html' 作为响应,'done' 回调也不会被触发。同样正如 jQuery-File-Upload 所说,我需要在上传完成后进行重定向以获取上传的文件 (https://github.com/blueimp/jQuery-File-Upload/wiki/Cross-domain-uploads),但这还没有完成。 任何帮助,将不胜感激。 问候。

【问题讨论】:

    标签: javascript jquery internet-explorer jquery-file-upload


    【解决方案1】:

    好的,所以我开始工作了。问题是在我的文件上传器配置中

    dataType: 'json'
    

    但由于 IE9 使用 iframe,它会发出 html 请求,并且响应具有 Content-Type 'text/html'。使用该配置,fileuploader 期望收到一个 json 响应,所以我的响应是我为测试而制作的失败回调。看看这篇帖子就知道了jQuery FileUpload doesn't trigger 'done'

    【讨论】:

    • 此修复可能会引发一些错误,请参阅我的解决方案以实际解决无副作用
    【解决方案2】:

    投票最多的答案不是最佳解决方案,可能会引发错误。实际上,对于 IE dataType,来自这篇(很棒的)文章:

    当 dataType 选项设置为 text、json、html 或 script 时, iframe 传输对响应执行一些处理。因为它 正在对从它使用的 iframe 获得的 DOM 对象进行操作, 但是,而不是原始 HTTP 响应数据,有可能 会弹出一些惊喜。

    http://missioncriticallabs.com/blog/2012/04/lessons-learned-from-jquery-file-upload/

    真正的解决方案:

    关于在 IE dataType 无关,只是缺少回调 add,它会在 fileupload 事件中强制文件推送。

    $('#file_file').fileupload({
        add: function (e, data) {
            data.submit(); //this will 'force' the submit in IE < 10
        },
        done: function (e, data) {
            alert('Done');
        }
    });
    

    【讨论】:

    • 对我来说这是正确的答案,因为将 dataType 设置为 json 会触发在现代浏览器中上传到 Amazon S3 时的失败回调(尽管修复了旧版浏览器 IE9),在大多数浏览器中都可以完全删除它.
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-07-24
    • 1970-01-01
    • 2011-09-10
    • 1970-01-01
    • 2018-05-05
    • 1970-01-01
    • 2012-05-24
    相关资源
    最近更新 更多