我正在尝试上传文件并返回有关文件属性(名称、大小等)的 json 响应。除了 IE 之外,它在所有浏览器中都可以正常工作。
IE 尝试将 JSON 作为文件下载!
我有 IE10 并通过从调试器更改浏览器模式和文档模式在 IE7 到 10 上进行测试。
我正在使用 asp.net mvc4,文件上传操作具有 HttpPost 属性,并且我使用返回 json 响应返回 Json(myObject);
这是我的 http 标头
Request
Key Value
Request POST /File/UploadFile/ HTTP/1.1
Accept text/html, application/xhtml+xml, */*
Referer http://localhost:63903/
Accept-Language en-NZ
User-Agent Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)
Content-Type multipart/form-data; boundary=---------------------------7dc1e71330526
Accept-Encoding gzip, deflate
Host localhost:63903
Content-Length 1377002
DNT 1
Connection Keep-Alive
Cache-Control no-cache
Response
Key Value
Response HTTP/1.1 200 OK
Server ASP.NET Development Server/11.0.0.0
Date Tue, 18 Dec 2012 23:44:19 GMT
X-AspNet-Version 4.0.30319
X-AspNetMvc-Version 4.0
Cache-Control private
Content-Type application/json; charset=utf-8
Content-Length 154
Connection Close
我尝试了一些建议,但到目前为止又回到了第一步!
您需要将 json 返回为text/html
因为 IE 不知道该怎么办application/json
内容..
return Json(myObject, "text/html");
不确定,但可能有效(如果确实如此,那就更正确了)使用text/x-json
return Json(myObject, "text/x-json");
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)