title: How do you conditionally export a CSV using ajax in laravel?
body: <p>I'm trying to export a CSV using the Laravel Excel Package <a href="https://docs.laravel-excel.com" rel="nofollow noreferrer">https://docs.laravel-excel.com</a>. 
  I need to pass a few variables in using an ajax request which is all working but the response isn't downloading the CSV. </p>
  
  <p>I'm using the package in a few places without ajax just a simple export and it's all working so I know that side is all good. </p>
  
  <p>Here is the ajax I'm using to send the data: </p>
  
  <pre><code>$(document).ready(function() {
  $( "#export" ).on( "click", function() {
                  let clubInfo = $("#clubInfo select").val();
                  let funderInfo = $("#funderInfo select").val();
                  $.ajax({
                      headers: {'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')},
                      type: 'post',
                      url: '{{route('export')}}',
                      data: {club : clubInfo, funder: funderInfo},
                  }).done(function(response) {
                      console.log(response);
                  }).fail(function() {
                      console.log("Failed");
                  });
              });
  });
  </code></pre>
  
  <p>Here is the controller that handle the export: </p>
  
  <pre><code>public function adminExport(Request $request)
      {
          $club = $request-&gt;input('club');
          $funder = $request-&gt;input('funder');
  
          return Excel::download(new UsersExport($club, $funder), 'users.xlsx');
      }
  </code></pre>
  
  <p>I'm not getting any PHP errors or warnings which is all good I'm just getting a response in the network tab which looks like it's the csv it's just not downloading. 
  The headers of the response are: </p>
  
  <pre><code>Accept-Ranges: none
  Cache-Control: public
  Connection: keep-alive
  Content-Disposition: attachment; filename=users.xlsx
  Content-Length: 6812
  Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
  </code></pre>