title: Download CSV file using "AJAX"
body: <p>I'm trying to accomplish a fairly simple task for my website, but I"m not sure exactly how to go about it. I want the user to be viewing a table, then click a button, at which point the user can save the contents of that table as a csv file. This request can sometimes be quite complicated so I generate a progress page to alert the user.</p>
  
  <p>I have most things figured out except actually generating the csv file. (I use jQuery and PHP)</p>
  
  <p>the jQuery code run on click:</p>
  
  <pre><code>hmis_query_csv_export: function(query_name) {
      $.uiLock('&lt;p&gt;Query Loading.&lt;/p&gt;&lt;img src="/images/loading.gif" /&gt;')
      $.get({
          url: '/php_scripts/utils/csv_export.php',
          data: {query_name: query_name},
          success: function(data) {
              $.uiUnlock();
          }
      });}
  </code></pre>
  
  <p>the relevant PHP:</p>
  
  <pre><code>header("Content-type: text/x-csv");
  header("Content-Disposition: attachment; filename=search_results.csv");
  //
  //Generate csv
  //
  echo $csvOutput
  exit();</code></pre>
  
  <p>What this does is sends the text as the PHP file, but it's doesn't generate a download. What am I doing wrong?</p>