title: Ajax and downloading CSV file
body: <p>I'm trying to build a "Export to CSV" system using ajax so 
  this is my ajax call</p>
  
  <pre><code>$(document).on('click', '#export-csv', function(){
      $.ajax({
          url: export_url,
          type: 'post',
          data:{ validations: validations },
          dataType: 'json',
          cache: false,
          timeout: 1000000,
          success: function (data) {
              var resp = data.response;
              console.log(resp);
          },
          error: function (error) {
              console.log(error);
          }
      });
  });
  </code></pre>
  
  <p>and this is my php code to convert an array to csv</p>
  
  <pre><code>public function exportCsvAction()
  {
      $request = $this-&gt;getRequest();
      if ($request-&gt;isPost()) {
  
          $input = $request-&gt;getPost();
          $response = $this-&gt;getResponse();
  
          $file = fopen('php://output', 'w');
          foreach ($input['validations'] as $line) {
              fputcsv($file, $line, chr(9), '"');
          }
          fclose($file);
  
          header('Content-type: text/csv; charset=utf-8');
          header('Content-Disposition: attachment; filename="validations-' . time() . '.csv"');
  
          return $response-&gt;setContent(\Zend\Json\Json::encode(array('response' =&gt; true)));
      }
      return $this-&gt;getResponse()-&gt;setStatusCode(400);
  }
  </code></pre>
  
  <p>Everything is working. My ajax returns success but now I'm stuck... </p>
  
  <p>How to download the file after a successfully ajax call? What is the next step?</p>
  
  <p>I already did my research and I found nothing relevant and/or helpful.</p>
  
  <p>Thanks in advance.</p>