最近用blueimp上传图片的时候,发现在ie下上传失败,总是提示下载文件。后研究发现,是由于ie8不支持aplication/json的缘故,故需要强制将ie的content-type设定为text/plain ,设置代码如下:
if (isset($_SERVER['HTTP_ACCEPT']) &&
(strpos($_SERVER['HTTP_ACCEPT'], 'application/json') !== false)) {
$response->headers->set('Content-type', 'application/json; charset=utf-8');
} else {
$response->headers->set('Content-type', 'text/plain; charset=utf-8');
}。
因为本人项目中用的是symfony2,对于项目返回的response的对象在eventLister中的onKernelResponse方法中做了统一处理,所以在control中修改header的content-type信息一直失败。后来才发现eventLister中有关于 这个统一设定。
参考资料:
ie 不支持 aplication/json :
https://github.com/blueimp/jQuery-File-Upload/issues/123
https://github.com/astaxie/beego/issues/165
http://stackoverflow.com/questions/13943439/json-response-download-in-ie710
https://github.com/blueimp/jQuery-File-Upload/issues/123
http://stackoverflow.com/questions/13943439/json-response-download-in-ie710
accept:Vary:
http://stackoverflow.com/questions/1975416/trying-to-understand-the-vary-http-header
http://keystonewebsites.com/articles/mime_type.php
http://www.456bereastreet.com/archive/200408/content_negotiation/
http://blogs.msdn.com/b/ieinternals/archive/2009/06/17/vary-header-prevents-caching-in-ie.aspx
http://blogs.msdn.com/b/ieinternals/archive/2009/06/17/vary-header-prevents-caching-in-ie.aspx