title: Downloading file though AJAX POST
body: <p>I'm trying to provide a simple download using AJAX POST request. A user clicks a <code>&lt;span&gt;</code> and the download begins (or a download dialog shows up, depending on the browser). I've implemented all this, but the AJAX response doesn't trigger any browser download behavior and I don't know why.</p>
  
  <p>Here's my code:</p>
  
  <p>HTML/twig:</p>
  
  <pre><code>&lt;span id="export_csv"&gt;csv - click me to download the file&lt;/span&gt;
  </code></pre>
  
  <p>javascript:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  $(document).ready(function() {
    $('#export_csv').click(function(){
      var params = "some params";
      $.ajax({
        type: 'POST',
        url:  "{{path('ExportBundle_export', {'format': 'csv','report' : 'basic'})}}",
        data: params
      });
    });
  });
  &lt;/script&gt;
  </code></pre>
  
  <p>Controller code (symfony2, but it doesn't matter here):</p>
  
  <pre><code>$response = new Response(file_get_contents($document-&gt;getPath()));
  $response-&gt;setStatusCode(200);
  $response-&gt;headers-&gt;set('Content-Type', $document-&gt;getMime());
  $response-&gt;headers-&gt;set('Content-Description', 'Submissions Export');
  $response-&gt;headers-&gt;set('Content-Disposition', 'attachment; filename='
      . $filename . '.' . $format);
  $response-&gt;headers-&gt;set('Content-Transfer-Encoding', 'binary');
  $response-&gt;headers-&gt;set('Pragma', 'no-cache');
  $response-&gt;headers-&gt;set('Expires', '0');
  return $response;
  </code></pre>
  
  <p>This is example request:</p>
  
  <pre><code>Request URL:http://myapp.local/app_dev.php/export/basic/csv
  Request Method:POST
  Status Code:200 OK
  </code></pre>
  
  <p>and response headers:</p>
  
  <pre><code>cache-control:private, must-revalidate
  Connection:close
  content-description:Submissions Export
  content-disposition:attachment; filename=report_1363013244.csv
  Content-Length:790
  content-transfer-encoding:binary
  Content-Type:text/csv; charset=UTF-8
  Date:Mon, 11 Mar 2013 14:47:24 GMT
  expires:0
  pragma:no-cache
  Server:Apache/2.2.22 (Ubuntu)
  x-debug-token:513dee7c99fdb
  X-Powered-By:PHP/5.3.10-1ubuntu3.5
  </code></pre>
  
  <p>I've checked <code>Network</code> tab in Google Chrome firebug-alike toolbar and the response looks exactly like the file. Maybe there is something wrong with my headers, but I checked them twice already...</p>
  
  <p>PS 1</p>
  
  <p>I'd like to make it using AJAX (I prefer it more than creating a HTML form).</p>
  
  <p>PS 2</p>
  
  <p>I've got lots of parameters in the client side layer (javascript). I need all of them to be available in the controller (server-side script). When using AJAX, I just pass them in the <code>data</code> key.</p>