问题描述
我看到过与此稍微相关的问题,但没有一个能回答我的问题.我已经设置了一个 Ext.Ajax.request 如下:
I have seen questions slightly related to this, but none that answer my problem. I have set up an Ext.Ajax.request as follows:
var paramsStringVar = 'param1=1¶m2=two¶m3=something¶m4=etc';
Ext.Ajax.request({
url: '/cgi-bin/url.pl',
method:'POST',
params:paramsStringVar,
timeout:120000,
success: function(response, opts){
var objhtml = response.responseText; //content returned from server side
console.log(objhtml);
}
});
此请求从后端检索适当的内容.一个参数是 outputType,它可以取值 {html, excel, csv}.当返回 html 显示时,我能够正确处理和显示它.现在解决问题...
This request retrieves the appropriate content from the backend. One parameter is outputType, which can take values {html, excel, csv}. When returning html to display I am able to handle and display it correctly. Now on to the problem...
当我将 outputType 参数设置为 csv 或 excel 时,我会根据要求将适当的内容作为 csv 或 tsv(excel) 取回.但是,我不想要内容,我想要提示下载文件(csv 或 excel).如何让浏览器自动提示用户下载文件,而不是仅仅检索 extjs 中的文本内容?
When I set the outputType parameter to csv or excel, I get back the appropriate content as csv or tsv(excel) as requested. BUT, I don't want the content, I want a prompt to download the file(csv or excel). How can I have the browser auto prompt the user to download the file instead of just retrieving the text content within extjs?
4.07 版,所以我不能使用任何 4.1 版的功能
Version 4.07 so I can't use any 4.1 only features
推荐答案
以下是我的解决方案.这就是我目前的工作方式.该响应基于 text/csv 的响应类型生成下载/打开提示.请注意,不需要 iFrame 或对 iframe 的引用.我花了很多时间挂断了对 iFrame 的需求,这实际上破坏了我的解决方案.生成下载提示不需要 iFrame.所需要的是一个与此类似的请求(提交),以及一个生成带有 text/csv 响应标头的适当 csv 的后端.
Below is my solution. This is how I have it currently working. The response generates a download/open prompt, based on a response type of text/csv. Note that no iFrame or reference to an iframe are needed. I spent a lot of time hung up on the need for an iFrame, which actually broke my solution. An iFrame is not needed to generate a download prompt. What is needed is a request(submittal) similar to this one, along with a backend generating the appropriate csv with text/csv response header.
var hiddenForm = Ext.create('Ext.form.Panel', {
title:'hiddenForm',
standardSubmit: true,
url: /cgi-bin/url.pl
timeout: 120000,
height:0,
width: 0,
hidden:true,
items:[
{xtype:'hiddenField', name:'field1', value:'field1Value'},
// additional fields
]
})
hiddenForm.getForm().submit()
standardSubmit 行很重要
The standardSubmit line is vital
这篇关于Extjs 4(下面有 3.4 的代码)下载从 post 请求返回的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论