简体   繁体   English

IE 8和9如果使用iframe,则尝试下载json响应

[英]IE 8 & 9 try to download json response if using iframe

I am using the blueimp fileUpload plugin to send files to the server and in ie 8 and ie 9 it tries to prompt me to download a file. 我正在使用blueimp fileUpload插件将文件发送到服务器,在8和9中,它试图提示我下载文件。 When I open the file it is perfect json. 当我打开文件时,它是完美的json。

I have tried setting the content type to text/plain as well as the dataType to text/plain but to no avail. 我尝试将内容类型设置为text / plain以及将dataType设置为text / plain但无济于事。

I am using FubuMVC as well so I cant just return a string. 我也使用FubuMVC,所以我不能只返回一个字符串。 If it is not json then it tries to render a view. 如果不是json,则尝试渲染视图。

var obj = {
            dataType: 'json',
            contentType: "application/json",
            url: uploadUrl,
            formData: formData,
            start: function(e, data) {
                $('#' + loadingDiv).dialog('open');
            },
            stop: function(e, data) {
                $('#' + loadingDiv).dialog('close');
            },
            add: function(e, data) {
                data.formData = obj.formData;
                data.submit();
            },

            always: function(e, data) {
                alert('done');
            }
        };

        $('#' + div).fileupload(obj);

If your action method returns a string, the content type is set to text/plain , and the browser should display a string instead of trying to download a file. 如果您的操作方法返回一个字符串,则内容类型将设置为text/plain ,并且浏览器应显示一个字符串,而不是尝试下载文件。

Or you can use IHttpWriter in your action method. 或者,您可以在操作方法中使用IHttpWriter

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

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