使用JQuery或JavaScript自动提交

I need to send a var which contains html code.

I have a file with html code, and I read it and put that HTML code in a var with

ob_start();
$output = ob_get_contents();
ob_end_clean();

I tried to send it via GET with header(location:); but I get the error (headers already sent). so I want to send it via JQuery or JavaScript.

I tried to do this

var output = $('#out').text(); 
        $.post('../tcpdf/examples/polizaPDF.php',{output:output})
    .done(function(data) 
    {
        console.log($.trim(data));
    });

But I need to stay in the page "polizaPDF.php".

What do I do in polizaPDF.php? I print the var output which contains the html code. So I can get a PDF in the browser. I use tcpdf to print the pdf.

Can anyone help me or give me some advice to do this?

You might want to check the documentation on Ajax calls. Here's an example on how to pass data to a file :

$.ajax({
    type: "GET",
    url: "../tcpdf/examples/polizaPDF.php",
    data: { output: output }
})
.done(function(data) {
    console.log($.trim(data));
});

Then on your polizaPDF.php you now have access to the php variable $_GET['output']

If you do POST with JQUERY AJAX, then it will send it to polizaPDF.php, and that script processes it.

I think by sending request through AJAX POST you will not receive PDF output. Because to receive PDF file output in browser, your PHP Script should send fresh HTTP Headers, and also you have to mention PDF in header.

You have to use this code to send PDF file to browser, and this needs fresh header.

header("Content-type:application/pdf");

Happy Coding Atul Jindal