开发者

How to receive csv or pdf file as response of a ajax request

开发者 https://www.devze.com 2023-03-23 18:56 出处:网络
I am using Django. I need to receive a pdf, csv or xls file as a reponse to a form I am submitti开发者_JS百科ng through ajax.

I am using Django.

I need to receive a pdf, csv or xls file as a reponse to a form I am submitti开发者_JS百科ng through ajax.

It is receiving the file when I am normally submitting the form, but when I do it through ajax it receives it but dosen't show download option.

I want to submit it through ajax to show a loading .gif as it take a lot of time.


The data that you get back from an AJAX request is really nothing more than text data. I don't think this is an easy thing to accomplish. What is the reason for the AJAX? Is it a long running process to generate? If it is then you can do a redirect in your javascript when the .csv or .xls is generated. If your doing the AJAX to just keep the user on the same page, then I would try submiting the form to a new target window.


create a hidden iframe, then in your ajax :

url: document.getElementById('myiframeid').src = your_server_side_url,

0

精彩评论

暂无评论...
验证码 换一张
取 消