I have the following client-side code:
var downloadUrl = buildRequestUrl();
window.open(downloadUrl, '_self');
That is working fine, but I need to pass some custom headers with the request, so I am using ajax, like this:
$.ajax(downloadUrl, {
headers: { 'custom-header': 'custom-header-value'},
type: 'GET',
contentType: 'application/octet-stream'
}).done(function (data) {
var blob = new Blob([data], { type: 'application/pdf' });
var link = window.document.createElement('a');
link.href = window.URL.createObjectURL(blob);
link.download = '';
link.click();
});
The file get downloaded, but the content is empty (3 blank pdf pages). What I am doing wrong ?