IE8将json响应视为文件,并尝试下载 [英] IE8 treats json response as file and tries to download it

查看:503
本文介绍了IE8将json响应视为文件,并尝试下载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用IE8,并且发送ajax请求到发送响应作为json的url。 ajax设置的jquery代码如下:

  $(document).ready(function(){
$ .ajax({
url:url_string,
dataType:json,
success:function(response){
alert('all are well');
},
错误:函数(请求,状态,错误){
alert(request);
alert(status);
alert(error);
}
});
});

我确信服务器正在发送JSON响应,但IE8将其视为文件并显示下载弹出窗口框。但是对于FF和Chrome,相同的过程可以正常工作。当我在 dataType



中将 json 替换为 jsonp 时,仍然会发生这种情况,但总是输入错误回调方法。



我的 json 响应正文由一个包含 html标签的字符串组成。



任何想法为什么会这样?



谢谢

解决方案

我有同样的问题,并通过在响应头中为所有IE请求设置Content-type =text / html(而不是application / json)来修复它



我还写了一篇关于它的博客文章,其中包含一些更多的信息: http://blog.degree.no/2012/09/jquery-json-ie8ie9-treats-response-as-downloadable-file/


I am using IE8 and I am sending ajax request to on of the url which sends back response as json. The jquery code for the ajax setup is given below:

$(document).ready(function(){
  $.ajax({
    url: url_string,
    dataType: "json",
    success: function(response){
      alert('all is well');
    },
    error: function(request, status, error){
      alert(request);
      alert(status);
      alert(error);
    }
  });
});

I am sure that the server is sending JSON response but IE8 treats it as file and brings up download popup box. But the same process works fine for FF and Chrome. This still happens when i replace json to jsonp in dataType

But it always enters into error callback method.

My json response body consists of a string with html tags too.

Any idea why is this happening?

Thanks

解决方案

I had the same issue and fixed it by setting Content-type = "text/html" in the response header for all IE requests (rather than "application/json")

I also wrote a blog post about it with some more information: http://blog.degree.no/2012/09/jquery-json-ie8ie9-treats-response-as-downloadable-file/

这篇关于IE8将json响应视为文件,并尝试下载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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