Error generating document with jQuery

0

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
    
asked by Francisco Núñez 29.01.2018 в 17:11
source

1 answer

0

Good day, I generate reports with html, in the following way: (Only there will be a popup window)

var report
report = window.open('report.html','reporte','width=612,     
height=1038,scrollbars=YES')
report.document.write("tu response");

I hope it helps you. Greetings.

    
answered by 02.02.2018 в 16:10