Reputation: 203
I am currently trying to download the file using ajax request from my REST based servie using browser as.
$('#button').click(function (url)
{
var xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
xhr.setRequestHeader('Authorization', "Bearer " + token);
xhr.onload = function(e) {
alert('success')
//what should I do here to get file downloaded using browser
};
xhr.send();
}););
Upvotes: 0
Views: 90
Reputation: 1828
you can use below code.
$('#button').click(function (url)
{
var xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
xhr.setRequestHeader('Authorization', "Bearer " + token);
xhr.onload = function(e) {
alert('success')
var file=e.target.files[0]; //you can get file this way.
};
xhr.send();
}););
Upvotes: 1