IE中Json响应下载(7~10) [英] Json response download in IE(7~10)

查看:18
本文介绍了IE中Json响应下载(7~10)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试上传文件并返回有关文件属性(名称、大小等)的 json 响应.它适用于除 IE 之外的所有浏览器.

I am trying to upload a file and return a json response regarding properties(name, size etc) of the file. It works fine in all browsers except IE.

IE 尝试将 JSON 作为文件下载!

IE tries to download the JSON as a file !

我有 IE10 并通过从调试器更改浏览器模式和文档模式在 IE7 到 10 上对其进行测试.

I have IE10 and testing it on IE7 to 10 by changing browser mode and document mode from the debugger.

我正在使用 asp.net mvc4,文件上传操作具有 HttpPost 属性,我正在使用 return Json(myObject);

I am using asp.net mvc4, the file upload action have HttpPost attribute and i am returning json response using return Json(myObject);

这是我的 http 标头

And here are my http headers

请求

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

回应

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

我尝试了一些建议,但到目前为止都回到了第一条!

I tried a few suggestions but so far back to square one !

推荐答案

您需要将 json 作为 text/html 返回,因为 IE 不知道如何处理 application/json 内容..

You will need to return the json as text/html since IE does not know what to do with application/json contents..

return Json(myObject, "text/html");

<小时>

不确定,但使用 text/x-json

return Json(myObject, "text/x-json");

这篇关于IE中Json响应下载(7~10)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆