title: return TCPDF after server post ajax issue
body: <p>I am trying to return a tcpdf after validating a form. If there is an error in validation the php file returns an error msg. If the validation succeeds I want to return the PDF.  Trouble is that when the pdf is returned it is not displayed as a PDF just garbage text. What change do I need to make in my code?</p>
  
  <p>Here is my ajax submit code:</p>
  
  <pre><code>    function postForm() {
      var ajaxRequest;
      /* Clear result div*/
      $("#result").html('');
      /* Get from elements values */
      var values = $("#matchReportForm").serialize()
      ajaxRequest= $.ajax({
              url: "mReport.php",
              type: "post",
              data: values,
              beforeSend: function() {
                      $('#result').html('&lt;img src="images/indicator.gif" alt="loading..." /&gt;');
                      $('#btnGo').attr("disabled", "disabled");
                      $("#txtSecurity").focus();
                  }
          });
  
       ajaxRequest.done(function (response, textStatus, jqXHR){
            // show successfully for submit message
            $("#result").html(response);
            $('#btnGo').removeAttr("disabled");
       });
  
       /* On failure of request this function will be called  */
       ajaxRequest.fail(function (){
         // show error
         $("#result").html(response);
         $('#btnGo').removeAttr("disabled");
       });
  
      }
  </code></pre>
  
  <p>In my PHP file I either echo an error msg or return the pdf:</p>
  
  <pre><code>    $pdf-&gt;writeHTML($report, true, false, true, false, '');
  
      $pdf-&gt;Output('match_report.pdf', 'D');
  </code></pre>