-1

I am trying to serve up a CSV file as the response to a get request.

If I go onto Dev tools -> Network I can see the CSV values in the response preview, and if I double click that it will download the file. However I can't seem to get it to download automatically.

I have messed around with every type of header I can think of.

Any ideas?

Response Headers

Charlie Lynch
  • 383
  • 3
  • 6

1 Answers1

0

Yes, It seems you can't get file downloads from ajax requests (Thanks to Quentin for the linked answer in the comments), at least not easily anyway.

This is because there is a subtle separation between the user and the browser. Ajax is triggered by the browser so the file is returned to the browser not the user.

A form submit on the other hand is triggered by the user and so the file is returned to the user (automatically downloading).

So in order to fix this I changed to a form with a post method with hidden inputs and it now works a treat.

Thanks all.

Charlie Lynch
  • 383
  • 3
  • 6