title: download pdf from ajax post
body: <p>I want to download a pdf file via a jquery post. I tried this:</p>
  
  <pre><code>$('#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></pre>
  
  <p>Code PHP:</p>
  
  <pre><code>&lt;?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'); 
  ?&gt;
  </code></pre>
  
  <p>When I use this code I get all strange signs in <code>#pdf_results</code>. I want to save the PDF to my computer but this doesnt work.</p>
  
  <p>Somebody knows how to fix this?</p>
  
  <p>Thanks in advance!</p>