解决IE浏览器中出现“Resource interpreted as Document but transferred with MIME type application/json”问题
在上传图片时,使用ajax提交,返回的数据格式为json。在测试时发现IE浏览器中,上传图片后,没有显示图片,而是弹出一个提示:是否保存UploadImg.json文件;而在其他浏览器中正常。
在Chrome中调试后发现,图片上传成功后,浏览器给出了一个警告:Resource interpreted as Document but transferred with MIME type application/json。
原来后台代码在返回json数据时,响应数据的ContentType默认为“application/json”,IE浏览器的新版本(IE10、IE11)会把该类型解释为文件下载操作。
后台代码:
public JsonResult UploadImgToLocal()
{
var FileMaxSize = ; //文件大小,单位为K
var model = new ImgUploadResult();
try
{
HttpPostedFile myFile = HttpContext.Current.Request.Files[];
if (myFile != null)
{
string fileExtension = myFile.FileName.Substring(myFile.FileName.LastIndexOf('.'));
if (!CheckValidExt(fileExtension))
{
return Json(new { UploadCode = , massege = "文件格式错误" });
}
else
{
if (myFile.ContentLength > FileMaxSize * )
{
return Json(new { UploadCode = , massege = "文件过大" });
}
else
{
//上传 //返回结果
return Json(new { UploadCode = , massege = "", sourceUrl = model.SourceImgUrl, bigUrl = model.BigImgUrl, thumbUrl = model.ThumbImgUrl });
}
}
}
else
{
return Json(new { UploadCode = , massege = "请上传文件" });
}
}
catch
{
return Json(new { UploadCode = , massege = "上传失败" });
}
}
将代码中的
return Json(new { UploadCode = , massege = "", sourceUrl = model.SourceImgUrl, bigUrl = model.BigImgUrl, thumbUrl = model.ThumbImgUrl });
改为:
JsonResult json = new JsonResult();
json.ContentType = "text/html";
json.Data = new { UploadCode = , massege = "", sourceUrl = model.SourceImgUrl, bigUrl = model.BigImgUrl, thumbUrl = model.ThumbImgUrl };
return json;
修改响应数据的ContentType类型后,返回的数据类型为json字符串,这样就会兼容IE浏览器了。
解决IE浏览器中出现“Resource interpreted as Document but transferred with MIME type application/json”问题的更多相关文章
- Resource interpreted as Document but transferred with MIME type application/json laravel异常请求返回警告
一般情况下,laravel在方法里可以向前端返回数组格式 return [], 框架可以自动将数组转成JSON字符串返回,但浏览器会报MIME类型警告, 如是做APP接口可以忽视该警告: 但在前端aj ...
- Resource interpreted as Document but transferred with MIME type application/json
转自:https://blog.csdn.net/just_lover/article/details/81207472 我在修改并保存后,界面返回提示“undifine”,实际我是看到有返回提示的. ...
- 移动端,点击a标签链接的pdf报错 Resource interpreted as Document but transferred with MIME type application/pdf
源码: <a href="11.pdf" class="actcont_a fl report_a" style="display: block ...
- Django 导入css文件,样式不起作用。Resource interpreted as Stylesheet but transferred with MIME type application/x-css
笔者今天在模板中加载css文件时,发现 css样式能够下载再来却无法起作用,而且,图片.js都能够正常使用. 并且 浏览器提示: Resource interpreted as Stylesheet ...
- odoo 错误 Resource interpreted as Stylesheet but transferred with MIME type application/x-css:
odoo8 页面内容显示一半, web 控制台显示错误 Resource interpreted as Stylesheet but transferred with MIME type ap ...
- Chrome 报 Resource interpreted as Script but transferred with MIME type text/plain 警告的解决办法
http://www.2cto.com/os/201312/262437.html 安装了VS2012之后,chrome在加载页面的时候会报 Resource interpreted as Scrip ...
- 样式加载不出来,浏览器控制台报错:Resource interpreted as Stylesheet but transferred with MIME type text/html
写登录的时候出现的问题,样式时好时坏,浏览器控制台看到的信息是: Uncaught SyntaxError: Unexpected token <Resource interpreted as ...
- Chrome: Resource interpreted as Font but transferred with MIME type font/x-woff
最近,项目中加入了Bootstrap进行界面优化,但是,项目加载运行之后,控制台总是提示以下错误信息: GET http://localhost:8080/.../fonts/fontawesome- ...
- Resource interpreted as Stylesheet but transferred with MIME type text/html: css失效
异常信息: Resource interpreted as Stylesheet but transferred with MIME type text/html: 可能原因 过滤器或者某个地方对所有 ...
随机推荐
- 在Linux文件清空的几种方法
在Linux文件清空的几种方法 1.使用重定向的方法 [root@centos7 ~]# du -h test.txt 4.0K test.txt [root@centos7 ~]# > tes ...
- 本地预览的vue项目,在githubpage静态展示
本地项目github静态展示 前提 在本地npm run dev后能够在本地端口正常显示 githubpage为自己的静态页面 上线 config/index.js中设置assetsPublicPat ...
- 2018/7/16 YMOI模拟 NOIP2013D2T3华容道
题目描述 Description 小 B 最近迷上了华容道,可是他总是要花很长的时间才能完成一次.于是,他想到用编程来完成华容道:给定一种局面,华容道是否根本就无法完成,如果能完成,最少需要多少时间. ...
- Struts2基础入门
Struts2基础入门 创建一个web工程 0)导包并且创建一个核心配置文件 <?xml version="1.0" encoding="UTF-8"?& ...
- 转:2018最全Redis面试题整理
Java面试----2018最全Redis面试题整理 1.什么是Redis? 答:Redis全称为:Remote Dictionary Server(远程数据服务),是一个基于内存的高性能key-va ...
- HttpServletRequest cannot be resolved to a type The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path
HttpServletRequest cannot be resolved to a type The superclass "javax.servlet.http.HttpServlet& ...
- Web前端开发面试技巧
Web前端开发面试技巧 面试前端工程师对我来说是一件非常有意思的事,因为面试过程很大程度上也是自我提升的过程.无论大公司还是小公司,之所以在如何招聘到真正有能力的,前端工程师方面会遇到同样的问题. 近 ...
- cx_freeze的安装使用
python是一个非常非常优秀的编程语言,它最大的特性就是跨平台.python程序几乎可以在所有常见的平台中进行使用,而且大部分无需修改任何代码!不过,python也有一点点小缺憾(这个是由于自身本质 ...
- 数据写入Excel
通过xlwt这个库,可以将数据写入Excel中,而且通过xlwt写excel格式可以控制 颜色.模式.编码.背景色 下面基本上是一个练习,熟悉如何操作xlwt库的 下面是代码,所有的内容,和介绍,基本 ...
- 小游戏banner广告流量量主指引
小程序导航 https://wq.xmaht.top