开发者

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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜