javascript - IE8 jquery json响应触发下载

标签 javascript jquery ajax internet-explorer internet-explorer-8

我希望 IE8 与以下将 ajax 请求返回为 json 的 jquery 一起工作:

$.ajax({
        url: formAction,
        type: 'post',
        dataType: 'json',
        data: form,
        success: function(data) {
            closeBlocker();
            if (data.count != 0) {
                $('#divid').toggle('slow');
            } else {
                $("#anotherdiv").css('display', 'none');
            }
            processSearchResult(target, data);
            reloadMap(data);
        }
});

在所有其他浏览器中,这会触发获取数据的调用。然而,在 IE8 中,这会导致弹出一个对话框,询问用户是否要下载文件。它看起来像这样:

enter image description here

我看到了this post但无法正确更改 ContentType。

如何在 IE8 中做同样的事情而不影响其他浏览器?谢谢你的想法!

最佳答案

我想这与 MIME type 有关.

您必须告诉浏览器将其视为文本/html。然后它不会尝试下载它,而是将其显示为文本。

为此,您可以在 header 中发送 Content-type = "text/html"

关于javascript - IE8 jquery json响应触发下载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19717756/

相关文章:

javascript - object.key 的跨浏览器

javascript - 访问 session 值

php - 在 JavaScript (jQuery) 中隐藏 ajax 路径

javascript - ng-disabled 在数据更改后不评估

javascript - jQuery AJAX。返回值未定义?

javascript - 取消输入时提交

javascript - 如何使此代码更有用(防止文本区域中出现特殊字符)

javascript - Angular 2 LocalStorage key

javascript - javascript 中的二维数组有点问题

javascript - 在无限循环中为通过视口(viewport)的元素设置动画的最佳方法