Tengo una funcion que hace una peticion a un endpoint de una API, esta api arma un pdf y responde, el problema es que aparece un mensaje de error en la peticion ajax:
Este es el error que obtengo como respuesta.
Uncaught DOMException: XMLHttpRequest.responseText getter: responseText is only available if responseType is '' or 'text'.
El codigo es el siguiente:
function ImprimirApiExterno(url, elemento = null) {
ShowModalCargando(true);
$.ajax({
cache: false,
contentType: "application/json",
type: "GET",
url: url,
processData: false,
xhrFields: {
responseType: "blob"
},
success: function (response, status, xhr) {
console.log("Operacion exitosa")
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));
}
});
}
- Ya intente omitir el
responseType
, y me entrega un pdf vacio - Intente usar una version de
JQuery
mas actual y no funciono (uso la 1.11.3) - Intente omitir el
contentType
, no funciono - Al parece ni siquiera pasa por el success
- Ya probe el mozilla, en google chrome y el error persiste
- Probando en postman, si funciona