I want to download a pdf file via a jquery post. I tried this:
$('#downloadPdf').click(function() {
var id = $('#fileId').val();
$.ajax({
type: "POST",
url: "includes/download_pdf.php",
data: 'file_id=' + id,
complete: function(data) {
$('#pdf_results').html(data.responseText);
}
});
});
Code PHP:
<?php
$file_name = $_POST['file_id'];
// We'll be outputting a PDF header('Content-type: application/pdf');
// It will be called downloaded.pdf header('Content-Disposition: attachment; filename="'.$file_name.'.pdf"');
// The PDF source is in original.pdf readfile('/var/www/vhosts/domain.nl/private/'.$file_name.'.pdf');
?>
When I use this code I get all strange signs in #pdf_results
. I want to save the PDF to my computer but this doesnt work.
Somebody knows how to fix this?
Thanks in advance!