Good afternoon, I have a problem that already has me head, no matter how hard I try to solve it, I have an HTML, which I want to send data to a PHP, so that the latter process it and with the FPDF class creates a PDF file, the data will come from some controls in HTML, that's why I will use JavaScript to send this data to PHP. When I execute it, it just sends a lot of characters to my page and does not create the PDF, is there a way to solve that problem? My code is as follows:
index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<script src="https://code.jquery.com/jquery-1.12.1.min.js"></script>
<script src="main.js"></script>
<button type="button" onclick="GenerarPDF()">click</button>
<div id="resulta"></div>
</body>
</html>
main.js
function GenerarPDF() {
$.ajax(
{
type: 'POST',
url: 'pdf.php',
data: {"saludo": "hola"}, //aquí le pasaré datos de controles de HTML
success: function (result) {
$('#resulta').html(result);
}
}
);
}
pdf.php
<?php
require_once('PDF/fpdf/fpdf.php');
$saludo = $_POST['saludo'];
$pdf = new FPDF('P', 'mm', 'Letter');
$pdf->AddFont('Courier', '');
$pdf->AddPage();
$pdf->SetFont('Courier', '', 11);
$pdf->Cell(50,10,$saludo);
$pdf->Output();
Thank you in advance to everyone.
P. D. Working with Windows 7 and PHP7.