Reputation: 5
On click on download button I need to "GET" an xml file from rest api url (http://localhost:xxxx/xx.xml) and save it on users desktop. How do I achieve this in javascript. Thanks.
Upvotes: 0
Views: 3481
Reputation: 3936
if you have control over the webhost, send the header:
Content-disposition: attachment; filename=x.xml
You could also use AJAX call and something like the downloadify flash object. Other than these there is no native way to force the downloading of a file
Upvotes: 0
Reputation: 4737
$('#your_button').click(function(){
window.open('http://localhost:xxxx/xx.xml');
return false;
});
Upvotes: 1