I am trying to send the HTML structure from an iframe via ajax POST
to php, but $_POST
is always null.
Ajax
function makePDF(){
var f = $('#iframe1');
var data = f.contents().find('body').html();
var html = escape(data);
alert(html);
$.ajax({
type: "POST",
url: "pdf.php",
data: {'html': html},
cache: false,
success:function(){
alert('done');
document.location.href='pdf.php';
},
error: function(){
alert('error');
}
});
}
This function is called via onClick.
HTML
<input id="btnpdf" class="btn btn-primary btnpdfh" type="button" value="Generate Preview as PDF" name="PDF" onClick="makePDF()">
pdf.php
<?php
echo 'Test<br>=';
$pdf = $_POST['html'];
echo $pdf;
?>
Firebug shows that the post request is made and the data was send but $pdf
stays empty, only the normal echo is displayed. I need the HTML structure of the iframe to generate an PDF
.
any help is appreciated, thanks.