404使用<iframe>和AJAX </iframe>下载文件

时间:2015-02-10 12:13:16

标签: jquery ajax iframe

我正在使用 iframe 通过AJAX请求从服务器下载excel文件。只要点击一个按钮,服务器就会在大约半分钟内创建一个excel文件 并将网址发送回客户端。我在 iframe “src”属性中设置网址的值

$("#ExportExcelFrame").attr('src', url);

即使文件存在,客户端也会抛出404错误,并且可以从生成的URL访问。

每当我对文件名进行硬编码(使用某些预先存在的文件的文件名)以消除处理延迟时,设置就会起作用并下载excel文件。

我试图将ajax请求的超时更改为无效

$.ajaxSetup({

    timeout: 120000 //Time in milliseconds

}); 

任何建议都将受到高度赞赏。

ajax电话

 jQuery.ajax({
                type: 'GET',
                url: 'Controller',
                data: {type: param, StartDate: StartDate, EndDate: EndDate, DateType:dateType,ResEstmBean: JSON.stringify(ResourceEstmBean)},
                beforeSend: function () {
                    $.blockUI({message: message, css: messageCss});
                },
                success: function (data)
                {


                        var fileName = data;

                        var url = "http://localhost:8080/WebApp/" + fileName;


                        $("#ExportExcelFrame").attr('src', url);

                        $.unblockUI();
                },
                        timeout: 300000,
                        error: function () {
                        $.unblockUI();
                        showErrorAlert();
                }
            });

1 个答案:

答案 0 :(得分:0)

我在2秒后设置了属性

setTimeout(function () {$("#ExportExcelFrame").attr('src', url)}, 2000);

现在正在工作。