title: Download a file built in PHP output buffer from AJAX call
body: <p>I am trying to build a CSV file in PHP, then call the PHP file from an AJAX call, which will then initiate a download of the CSV file upon success of the AJAX call.  This works fine if I save a physical copy of the .csv on the server, but I would like to use <code>php://ouput</code> so I do not have to worry about physical files clogging up the server.  Is it possible to initiate a download from returning <code>php://output</code> to AJAX?  Here is my code:</p>
  
  <p>HTML/jquery:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  
  &lt;html lang="en"&gt;
      &lt;head&gt;
          &lt;meta charset="utf-8" /&gt;
          &lt;script type="text/javascript" language="javascript" src="jquery.js"&gt;&lt;/script&gt;
          &lt;script type="text/javascript"&gt;
               $("#download").live("click", function() {
                  var request = $.ajax({
                      dataType: 'html',
                      url: 'php.php',
                      success: function(response) {
                          alert('Finished');
                      }
                  })
              })
          &lt;/script&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;h1 id="download"&gt;DOWNLOAD&lt;/h1&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>PHP:</p>
  
  <pre><code>&lt;?php 
      header('Content-type: application/vnd.ms-excel');
      header('Content-disposition: attachment; filename="test.csv"');
      $f = fopen('php://output', 'w');
      fwrite($f,'this,is,a,test');
      fclose($f);
      readfile('php://output');
      return;
  ?&gt;
  </code></pre>
  
  <p>I am not sure how to get this to return a File Save dialog from my AJAX call.</p>
  
  <p>This has to be simple, but I can't seem to find any examples that combines these two issues.</p>