dojo.io.iframe and download of Excel/PDF

心不动则不痛 提交于 2019-12-13 00:45:20

问题


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.

This is the call:

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

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

What am I doing wrong?


回答1:


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);


来源:https://stackoverflow.com/questions/4570559/dojo-io-iframe-and-download-of-excel-pdf

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!