I'm making an AJAX request to the server and getting a response as XML text and I've tried a bunch of ways to transform it into a downloadable file but none are working.
I've done something similar for a pdf but the difference is that for the pdf the content is returned as a blob, here's the code:
$.ajax({
method: "GET",
beforeSend: function(request) {
request.setRequestHeader("Authorization", bearer));
},
url: url,
xhrFields: {
responseType: "blob"
},
success(blob) {
var link = document.createElement("a");
link.href = window.URL.createObjectURL(blob);
link.download = "file.xml";
link.click();
}
});
How can I transform this code so it works the same way when receiving XML text?
request.setRequestHeader("Content-Type", "application/pdf");makes no sense. You are making a GET request. The body has no content to describe the type of.file.pdftofile.xml). It should just work. What's the problem?