IE8将json响应视为文件,并尝试下载 [英] IE8 treats json response as file and tries to download it
问题描述
$(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屋!