dojo.io.iframe和Excel / PDF下载 [英] dojo.io.iframe and download of Excel/PDF

查看:312
本文介绍了dojo.io.iframe和Excel / PDF下载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用Dojo按钮下载Excel或PDF文件。到目前为止,我已经设法通过在 onClick 处理程序中调用 dojo.io.iframe 按钮。但是,这只会下载一次文件。任何连续的电话将被忽略。

I would like to use a Dojo button to download an Excel or a PDF file. So far I've managed to do it by using a call to dojo.io.iframe in the onClick handler of the button. However, this will only download the file once. Any successive calls will be ignored.

这是调用:

function exportToExcel() {
    dojo.io.iframe.send({
        url: '/report/export',
        handleAs: 'xml',
        content: {
            __export: 'excel'
        }
    });
}

如同 dojo.io.iframe 不考虑先前的请求完成。

As if the dojo.io.iframe does not consider the previous request to be completed.

我做错了什么?

推荐答案

如果您使用 dojo.io.iframe.send ,则响应应以某种格式告诉dojo请求完成。响应应该包装在HTML文档的< textarea> 元素中。在你的情况下,响应是二进制流,所以dojo不知道请求是否完成。如果您没有指定超时,dojo将永远等待。

If you use dojo.io.iframe.send, then the response should be in certain format to tell dojo that the request is completed. The response should be wrapped in the <textarea> element of a HTML document. As in your case, the response is a binary stream, so dojo didn't know whether the request is completed. If you didn't specify a timeout, dojo will wait forever.

要实现该任务,您可以使用以下方法:

To achieve the task, you can use following approach:

var downloadPdfIframeName = "downloadPdfIframe"; 
var iframe = dojo.io.iframe.create(downloadPdfIframeName);
dojo.io.iframe.setSrc(iframe, url, true);

这篇关于dojo.io.iframe和Excel / PDF下载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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