简体   繁体   English

IE8提示下载json响应

[英]IE8 prompts download json response

I've been trying out the jquery form plugin and it works wonderfully. 我一直在尝试jquery表单插件,并且效果很好。 Oh, except for IE8. 哦,除了IE8。 It's always ie8. 一直是ie8。

Anyways, on the success response callback, ie8 prompts me to download the response instead of actually calling the success function. 无论如何,在成功响应回调中,ie8提示我下载响应,而不是实际调用成功函数。

Here is what my javascript code looks like 这是我的JavaScript代码的样子

 $("#form1").ajaxForm({
                url: "http://localhost:4887/api/file/POST",
                type: "POST",                 
                success: function (data)
                {
                    //response stuff here                   
                }
            });

I've tried specifying the datatype for the ajax form, but woe is me, it didn't work 我尝试为ajax表单指定数据类型,但我是可悲的,它没有用

The only thing I am returning from the server is just a string. 我从服务器返回的唯一内容就是一个字符串。 Once again, IE8 prompts me to download this string instead of just calling the success function. IE8再次提示我下载此字符串,而不仅仅是调用成功函数。 After some research, I understand that I might have to modify the http headers? 经过研究,我了解可能需要修改http标头? Could anyone shed some light on this? 有人能对此有所启示吗? Or give another way of going about this? 或给出另一种解决方法?

UPDATE Here is a brief look at the C# controller 更新这里是C#控制器的简要介绍

public class fileController : ApiController
{     
    public JsonResult POST()
    {
        HttpPostedFile file = null; 


       string encodedString = //do stuff here to get the base64 string

        ModelName obj = new ModelName();

        obj.characters = encodedString;
        JsonResult result = new JsonResult();
        result.Data = obj;
        result.ContentType = "text/html";

        return result;

    }

Request Headers... 请求标题...

Accept application/x-ms-application, image/jpeg, application/xaml+xml, image/gif, image/pjpeg, application/x-ms-xbap, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, / 接受application / x-ms-application,image / jpeg,application / xaml + xml,image / gif,image / pjpeg,application / x-ms-xbap,application / vnd.ms-excel,application / vnd.ms-powerpoint ,应用程序/ msword, /

Accept-Language en-US 美国接受语言

User-Agent Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; InfoPath.3; .NET CLR 1.1.4322) 用户代理Mozilla / 4.0(兼容; MSIE 8.0; Windows NT 6.1; WOW64; Trident / 4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; InfoPath.3; .NET CLR 1.1.4322)

Content-Type multipart/form-data; 内容类型多部分/表单数据; boundary=---------------------------7dd3e622907b6 边界= --------------------------- 7dd3e622907b6

Accept-Encoding gzip, deflate 接受编码gzip,放气

Proxy-Connection Keep-Alive 代理连接保持活动

Content-Length 300 内容长度300

Response Headers HTTP/1.1 200 OK Cache-Control no-cache 响应标头HTTP / 1.1 200 OK缓存控制无缓存

Pragma no-cache 语法无缓存

Content-Type application/json; 内容类型application / json; charset=utf-8 字符集= utf-8的

Expires -1 过期-1

Server Microsoft-IIS/8.0 服务器Microsoft-IIS / 8.0

X-AspNet-Version 4.0.30319 X-Powered-By ASP.NET X-AspNet-Version 4.0.30319 X-Powered-by ASP.NET

try this: 尝试这个:

[HttpPost]
public JsonResult POST()
{
    HttpPostedFile file = null; ;
    string encodedString = //get the file contents, and get the base64 encoded string        
    ModelName obj= new ModelName();
    obj.characters = encodedString;
    return   Json(obj, "text/html");

}

Update: 更新:

Or change the content-type 或更改内容类型
Response.Content.Headers.ContentType = new MediaTypeHeaderValue("text/html");

example: 例:

public JsonResult POST()
    {
        HttpPostedFile file = null; ;
        string encodedString = //get the file contents, and get the base64 encoded string        
        ModelName obj= new ModelName();
        obj.characters = encodedString;
        Response.Content.Headers.ContentType = new MediaTypeHeaderValue("text/html");
        return   Json(obj, "text/html");

    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM