开发者

Javascript : File download option from file made of data from browser side

开发者 https://www.devze.com 2023-04-11 13:52 出处:网络
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.

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.

0

精彩评论

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

关注公众号