Javascript 文件下载-ExtJs 4.2.3
我使用的是ExtJS4.2.3。 在我的web应用程序中,我需要下载文件。 为了做到这一点,我使用了一个在post中定义的“FileDownloader”组件 代码是:Javascript 文件下载-ExtJs 4.2.3,javascript,extjs,download,Javascript,Extjs,Download,我使用的是ExtJS4.2.3。 在我的web应用程序中,我需要下载文件。 为了做到这一点,我使用了一个在post中定义的“FileDownloader”组件 代码是: Ext.define('myApp.FileDownload', { extend: 'Ext.Component', alias: 'widget.FileDownloader', autoEl: { tag: 'iframe', cls: 'x-hidden', src
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的问题,这是服务器的响应。看到这个了吗