javascript jQuery-File-Upload 未在 Internet Explorer (IE9) 中触发完成回调
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19300804/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
jQuery-File-Upload not firing done callback in Internet Explorer (IE9)
提问by Ricardo Braz?o
i checked some questions regarding the same issue, blueimp jquery file upload - "done", "complete" callbacks not working for IE 9, but even after putting my Content-Type as 'text/html' as the response the 'done' callback isn't being fired. Also as the jQuery-File-Upload says i need to have a redirect to get the uploaded file (https://github.com/blueimp/jQuery-File-Upload/wiki/Cross-domain-uploads) after the upload is done, but that isn't also being done. Any help would be appreciated. Regards.
我检查了一些关于同一问题的问题,blueimp jquery 文件上传 - “完成”,“完成”回调不适用于 IE 9,但即使在将我的内容类型作为“文本/html”作为响应后,“完成”回调没有被解雇。同样,正如 jQuery-File-Upload 所说,我需要在上传完成后进行重定向才能获取上传的文件(https://github.com/blueimp/jQuery-File-Upload/wiki/Cross-domain-uploads) ,但这还没有完成。任何帮助,将不胜感激。问候。
回答by Ricardo Braz?o
ok so i go it working.The problem was that in the fileuploader configuration i had
好的,所以我开始工作了。问题是在我的 fileuploader 配置中
dataType: 'json'
but since IE9 uses the iframe it makes a html request, and the response has the Content-Type 'text/html'. With that configuration the fileuploader is expecting to receive a json response so my response was going to a fail callback i made just for testing. Got it working by looking at this post jQuery FileUpload doesn't trigger 'done'
但由于 IE9 使用 iframe,它会发出一个 html 请求,并且响应的内容类型为“text/html”。使用该配置,fileuploader 期望收到一个 json 响应,因此我的响应将转到我仅为测试而制作的失败回调。通过查看这篇文章让它工作jQuery FileUpload 不会触发“完成”
回答by Wagner Leonardi
The most voted answer isn't the best solution and can throw errors.Actually, setting dataType
isn't recommended for IE < 10, from this (awesome) article:
投票最多的答案不是最佳解决方案,可能会引发错误。实际上,dataType
不建议为 IE < 10 设置,来自这篇(很棒的)文章:
When the dataType option is set to text, json, html, or script, the iframe transport performs some processing of the response. Because it is operating on a DOM object obtained from the iframe it uses, however, and not the raw HTTP response data, there is the potential for some surprises to pop up.
当 dataType 选项设置为 text、json、html 或 script 时,iframe 传输会对响应执行一些处理。然而,因为它是在从它使用的 iframe 获得的 DOM 对象上操作的,而不是原始的 HTTP 响应数据,所以有可能会弹出一些惊喜。
http://missioncriticallabs.com/blog/2012/04/lessons-learned-from-jquery-file-upload/
http://missioncriticallabs.com/blog/2012/04/lessons-learned-from-jquery-file-upload/
Real solution:
真正的解决方案:
The "thing" about not firing in IE < 10 isn't related with dataType
, is just the lack of callback add
that forces the file push in fileupload event.
在 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');
}
});