i'm using ajax to make a request to an API, API makes a pdf a response with the file, but the ajax request return this error:
Uncaught DOMException: XMLHttpRequest.responseText getter: responseText is only available if responseType is '' or 'text'.
this is the code:
`
$.ajax({
cache: false,
contentType: "application/json",
type: "GET",
url: url,
processData: false,
xhrFields: {
responseType: "blob"
},
success: function (response, status, xhr) {
console.log("succuess")
console.log(response)
console.log(status)
console.log(xhr)
try {
//ShowModalCargando(false);
let blob = new Blob([response], { type: 'application/pdf' });
let URL = window.URL || window.webkitURL;
let downloadUrl = URL.createObjectURL(blob);
if (elemento === null)
window.open(downloadUrl);
else {
let iFrame = document.getElementById(elemento);
iFrame.src = downloadUrl;
}
} catch (ex) {
ShowModalCargando(false);
console.log(ex);
}
},
error: function (err) {
ShowModalCargando(false);
console.log("Error al intentar realizar la impresion: " + JSON.stringify(err));
}
});
`
- i tried skip the
content-type
, did not work - i tried to skip the
xhr response type
, and response with a empty pdf - tried with a newest version of jquery and did not work (i'm using Jquery 1.11.3
- I test in chrome and mz and did'nt work
- Using postman works.