使用Ext.js中的ajax请求从浏览器中打开或保存Excel文件附件 [英] Open or save the excel file attachment from the browser using ajax request in Ext.js
问题描述
我正在服务器端生成excel文件,并使用以下响应头将其写入
outpuststream。
I am generating the excel file in server side and writing it to the outpuststream with the following response headers.
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-Disposition","attachment;filename="+fileName);
在我的客户端:ajax调用servlet如图所示:
In my client side : An ajax call to the servlet as shown :
Ext.Ajax.request({
url: 'GenerateReport',
method: 'GET',
params: {
'start_date': sd.getValue(),
'end_date':ed.getValue()
}
});
浏览器显示以下响应头:
我的问题:打开和保存对话框提示未打开。可能是问题。请帮助我解决这个。任何帮助是赞赏。谢谢。$ /
My Issue : The Open and Save dialog prompt is not opening.What may be the problem.Please help me resolve this.Any help is appreciated.Thanks.
推荐答案
感谢@liya。我已经通过使用iframe而不是ajax调用解决了它。它直接下载
。它是:
Thanks @liya. I have resolved it by using iframe instead of ajax call.Its getting downloaded directly.Here it is :
Ext.core.DomHelper.append(document.body, {
tag : 'iframe',
id : 'downloadIframe',
frameBorder : 0,
width : 0,
height : 0,
css : 'display:none;visibility:hidden;height:0px;',
src : 'GenerateReport'
});
但是,无论如何,在下载之前打开一个对话框,提示
OPEN或保存文件,而不是直接保存我是
。
But Is their anyway,to open a dialog box before downloading,to prompt for 'OPEN' or 'SAVE' the file instead of saving it directly which I am doing.
这篇关于使用Ext.js中的ajax请求从浏览器中打开或保存Excel文件附件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!