0

When i do a JSON call , i get contents of a file. What i want is that , when pressed a button , this content should be downloadable as a file to the user.

So its like from web UI , browser side ,

my code fires a JSON request and i get some data as reply. This data should be down-loadable as a file

Vineeth Mohan
  • 18,633
  • 8
  • 63
  • 77
  • Is this what you're looking for? [How to create a “save as” button?](http://stackoverflow.com/questions/2849500/html-how-to-create-a-save-as-button) – Richard JP Le Guen Oct 05 '11 at 18:20

1 Answers1

1

You will need to send the the following http header in the response to tell the browser to download:

Content-Disposition: attachment; filename="download.json"

Of course when making a JSON call from Javascript to evaluate the response you won't need that header. The easiest way is probably to check for the X-Requested-With. If it is set it is probably a request made by JavaScript.

Daff
  • 43,734
  • 9
  • 106
  • 120