[英]File download - ExtJs 4.2.3
我正在使用ExtJs 4.2.3。 在我的Web應用程序中,我需要下載文件。 為了做到這一點,我使用的是在postFileDownloader中定義的“ 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),它什么也不做。
我認為這與Extjs或js無關,這是服務器的響應。 看到此下載文本文件,而不是在瀏覽器中打開
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.