通过AJAX下载CSV [英] Downloading CSV via AJAX
问题描述
您可以使用AJAX来从Web应用程序下载一个生成的CSV文件?如果是的话没有任何人有任何种类的参考,我可以指向了?
Can you use AJAX to download a generated csv file from a web application? If so does anyone have any kind of reference that I could be pointed towards?
编辑:对不起,我应该提到,我使用Prototype的Ajax.Request的,我看着萤火虫的反应工具和生成CSV是响应,我只需要得到它弹出的保存文件的选项已经生成后,由Ajax.Request的
Sorry I should have mentioned I am using Prototype's Ajax.Request and I looked in firebug's response tool and the generated CSV is the response, I just need to get it to pop up with the save file option after has been generated by the Ajax.Request
推荐答案
这是Ajax请求的一个已知的限制,您将需要使用JS这样的:
This is a known limitation of Ajax requests, you will need to use JS like:
window.location='download-csv.rb';
而不是使用一个Ajax请求
。另一种方法是改变一个隐藏的iframe的位置,但是这有它自己的亲的/反对的。
Instead of using an Ajax request. Another way is to change the location of a hidden Iframe, but this has it's own pro's/con's.
您将永远不会得到一个Ajax请求来显示'文件保存'对话框,不管你发送的HTTP标头。
You will never get an Ajax request to display the 'file save' dialog, no matter what HTTP headers you send.
这篇关于通过AJAX下载CSV的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!