title: File Download Operation By Ajax
body: <p>A dynamically generated files (According to user inputs) need to be downloaded...</p>
  
  <p>I have been using mPDF (php module to create pdf files).</p>
  
  <p>gen.php</p>
  
  <pre><code>require("./MPDF56/mpdf.php");
  $mpdf=new mPDF();
  $mpdf-&gt;WriteHTML('&lt;p&gt;Hallo World&lt;/p&gt;');
  $mpdf-&gt;Output('filename.pdf','I');
  </code></pre>
  
  <p>This scripts works perfectly. Output method can have several options Like </p>
  
  <pre><code>'F' : to save pdf to local.
  'S' : to return file as string.
  'D' : to download the file.
  'I' : force download... plug-in if available.
  </code></pre>
  
  <p><a href="http://mpdf1.com/manual/index.php?tid=125" rel="nofollow">http://mpdf1.com/manual/index.php?tid=125</a></p>
  
  <p>whenever a browser read the gen.php. pdf file will be downloaded. As i said it works perfectly ...</p>
  
  <p><strong>Until ,</strong> i try to do this with ajax.</p>
  
  <p>This script...</p>
  
  <pre><code>$.ajax({
    type:           'POST',
    cache:          false,
    url:            './gen.php',
    data:           JSON.stringify(inps),
    contentType:    'application/json',
  });
  </code></pre>
  
  <p>triggers the gen.php. PDF file is created. However, file is not sent to the browser.</p>
  
  <p>If i add this to the ajax part...</p>
  
  <pre><code>success: function(response){
    $("#result").html(response);
  }
  </code></pre>
  
  <p>Document receives the file as a string.
  I tried all the options of the mPDF.OUTPUT function . no result.</p>
  
  <p><strong>I thought a work around but i dont know how to achive it.</strong></p>
  
  <p>Ajax need to open a pop-up while it sends the data. So File-download operation will be done under another tag.</p>
  
  <p>Or maybe. I can try to open a invisible iframe of gen.php and send the data after i frame created...</p>
  
  <p>Any suggestion will help. </p>
  
  <p><strong><em>SHORTLY</em></strong></p>
  
  <p>How can ajax call a php file (that downloads a file). After the necessary data is sent.</p>