title: How to download a pdf using ajax and TCPDF
body: <p>My code works fine when I run the php script without ajax as a GET request.  I get prompted to download the rendered pdf and all is well.  However, I need to use ajax because I need to send more info from an html page to the php script than can be handled in a GET request.</p>
  
  <p>What do I need to put into my ajax to make this work?</p>
  
  <p>Thanks  </p>
  
  <p>js</p>
  
  <pre><code>function makePDF()
  {
  var x;
  if(window.event) // IE8 and earlier
      {
      x=event.keyCode;
      }
  else if(event.which) // IE9/Firefox/Chrome/Opera/Safari
      {
      x=event.which;
      }
  keychar=String.fromCharCode(x);
  
  alert(keychar);
  
  if (keychar == 'p' || keychar == 'P')
  {
      var charSheetHTML = characterSheet.innerHTML;
  
      $.ajax({ 
       url: 'pdf.php',
       data: {'charactersheet': charSheetHTML,},
       type: 'post',
       success: function (data) {**WHAT_DO_I_PUT_HERE??**},
       error: function (data) { alert("error\n" + data.toString()); }
      });
  }
  }
  </code></pre>
  
  <p>pdf.php</p>
  
  <pre><code>&lt;?php
  include_once( "bxcharacter/PDFChar.php.inc" );
  PDFChar();  
  ?&gt;
  </code></pre>
  
  <p>PDFChar.hph.inc</p>
  
  <pre><code>&lt;?php
  
  require_once('./tcpdf/tcpdf.php');
  
  function PDFChar(){
  
  
   $pdf = new TCPDF();
  
  
   $pdf-&gt;AddPage('P');
   $pdf-&gt;writeHTML($_POST['charactersheet']);
  
  
   $pdf-&gt;Output("character.pdf", 'D');
  
  
  }
  
  ?&gt;
  </code></pre>