jQuery-File-Upload未在Internet Explorer(IE9)中触发完成回调

Ric*_*zão 7 javascript jquery internet-explorer jquery-file-upload

我检查了一些有关同一问题的问题,blueimp jquery文件上传 - "完成","完成"回调不适用于IE 9,但即使把我的Content-Type作为'text/html'作为响应'完成'回调没有被解雇.同样,jQuery-File-Upload说我需要重定向才能在上传完成后获取上传的文件(https://github.com/blueimp/jQuery-File-Upload/wiki/Cross-domain-uploads) ,但这还没有完成.任何帮助,将不胜感激.问候.

Ric*_*zão 10

好的,所以我去工作.问题是在我的fileuploader配置

dataType: 'json'
Run Code Online (Sandbox Code Playgroud)

但由于IE9使用iframe,它会发出一个html请求,而响应的内容类型为"text/html".有了这个配置,fileuploader就会收到一个json响应,所以我的响应是为了测试而进行的失败回调.通过查看这篇文章得到它工作jQuery FileUpload不会触发'完成'


Wag*_*rdi 7

投票最多的答案不是最佳解决方案,可能会引发错误.实际上,dataType不建议IE <10,从这篇(很棒的)文章中进行设置:

当dataType选项设置为text,json,html或script时,iframe传输会执行响应的某些处理.因为它是在从它使用的iframe获取的DOM对象上运行,而不是原始HTTP响应数据,所以可能会出现一些意外情况.

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

真正解决方案

关于不在IE <10中触发的"事物"与之无关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');
    }
});
Run Code Online (Sandbox Code Playgroud)