I have a WS that returns a binary response.
What i need is when i request the service through ajax request, getting the response and generate again the original pdf.
However i can generate the pdf, but i don't know why i'm not getting the pdf content.
$.ajax({
url: resource_str,
type: "GET",
async: true,
},
success: function(data) {
var file = new Blob([data], {type: 'text/plain'});
var fileURL = URL.createObjectURL(file);
window.open(fileURL);
var a = document.createElement("a");
a.href = fileURL;
a.download = "Testing.pdf";
document.body.appendChild(a);
a.click();
$(window).on('focus', function(e) {
$('a').remove();
});
},fails: function (data){
console.log('Error');
}
})
what am i doing wrong? Why i'm losing the content?
i'm debating with this question for a while. Everything i need is to stream the pdf as binary from the WS and next be able to generate the pdf again using jquery.