Javascript : File download option from file made of data from browser side
When i do a JSON call , i get contents of a file. What i want is that , when pressed a 开发者_如何学JAVAbutton , 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
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.
精彩评论