I dont think, there is an issue with your ajax call. Your $.post
appears to be fine. But the issue might be because of your success callback handler.
You are setting the pdfajax.php as the source of your iframe after your ajax request has completed successfully, which doesn't make any sense. Because, this would trigger a new GET request to the URL 'pdfajax.php' and it wouldn't contain any request parameters at all.
Ideally, your data object would be containing the response received from 'pdfajax.php' which you can use to display within a div or so.
function( data ){
$('#report_result').html(data); // this can be used for html response not for pdf.
}
But in case, you want the data in your iframe, i don't think there is a need for Ajax. You can directly set the src for the iframe as shown below.
$(".pdf-report").dialog({
autoOpen: false,
modal: true,
draggable: true,
resizable: true,
width: 700,
height: 650,
dialogClass: "no-close",
buttons: {
"PDF": function(){
var send_html = $('#report_result').html();
$('#ireport_result').prop('src', 'pdfajax.php?code='+send_html);
},
"Close": function() {
$(this).dialog("close");
}
}
});
And your php file has few issues. The request parameter is code
not send_html
and your request type is GET
not POST
.
require_once 'core/init.php';
require_once 'tcpdf/tcpdf.php';
$html = input::get('code');
$method = $_SERVER['REQUEST_METHOD'];
if(strtolower($method) == 'get'){
$pdf = new TCPDF();
$pdf->AddPage();
$pdf->writeHTML($html, true, false, false, false, 'C');
$pdf->Output('example_001.pdf', 'I');
}