【问题标题】:File download - ExtJs 4.2.3文件下载 - ExtJs 4.2.3
【发布时间】:2015-09-23 09:55:42
【问题描述】:

我正在使用 ExtJs 4.2.3。 在我的网络应用程序中,我需要下载文件。 为了做到这一点,我使用了在 post 中定义的“FileDownloader”组件 fileDownloader

代码是:

Ext.define('myApp.FileDownload', {
   extend: 'Ext.Component',
   alias: 'widget.FileDownloader',
   autoEl: {
      tag: 'iframe',
      cls: 'x-hidden',
      src: Ext.SSL_SECURE_URL
},

load: function(config) {

    var e = this.getEl();
    e.dom.src = config.url +
        (config.params ? '?' + Ext.Object.toQueryString(config.params) : '');

        console.log('in FileDownloader - src: ' + e.dom.src);

        e.dom.onLoad = function() {
        if(e.dom.contentDocument.body.childNodes[0].wholeText == '404') {
            Ext.Msg.show({ 
                title: 'Attachment missing',
                msg: 'File cannot be found on the server !',
                buttons: Ext.Msg.OK,
                icon: Ext.MessageBox.ERROR
            });
        };
    };

}

});

我通过代码调用它:

downloader.load({
   url: src
});

其中 src 是文件的完整路径。

如果我下载 Word、Excel、PDF 文件,它运行良好,文件引用在浏览器的下载栏中可视化,但对于其他数据类型(例如 .txt、.jpg),它什么也不做。

【问题讨论】:

    标签: javascript extjs download


    【解决方案1】:

    我认为这不是关于Extjs或js的问题,而是服务器的响应。看到这个download the text file instead of opening in the browser

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-25
      • 1970-01-01
      相关资源
      最近更新 更多