I am trying to generate a document in the following way:
I have an ajax and the answer that should come in html code I want to recreate it in a separate window and print it:
$.ajax(
{
type: "POST", async: false, url: "index.php", data: data,
error: function (xhr, status, error) {
console.log(error);
},
success: function (response) {
//generamos el documento
printWindow = window.open('', 'Interface de Impresion');
printWindow.document.write(response);
printWindow.document.close();
}
});
Update
deepening the code apparently of the following two lines the second one tries to access the document property, and does not exist, as it is possible if the object is created with the first line.
printWindow = window.open('','Interface de Impresion');
printWindow.document.write(response); //Linea del Error
But I load the following Error a few times; sometimes load correctly:
Uncaught TypeError: Cannot read property 'document' of null