user1580577
user1580577

Reputation: 5

Get File and download from rest api

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

Answers (2)

SReject
SReject

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

Jeff Gortmaker
Jeff Gortmaker

Reputation: 4737

$('#your_button').click(function(){
    window.open('http://localhost:xxxx/xx.xml');
    return false;
});

Upvotes: 1

Related Questions