title: Export CSV using Laravel via Ajax
body: <p>I have a export csv function, it worked fine with laravel. But now I want to call export function via ajax and use method post, but I there is no respone. I can send a variable from laravel controller to response, but can not send a file download.</p>
  
  <p>Here is my code :</p>
  
  <p><strong>route.php</strong></p>
  
  <pre><code>    Route::get('/title/show', 'TitleController@show');
      Route::post('/title/show', 'TitleController@exportFromDB');
  </code></pre>
  
  <p><strong>show.blade.php</strong></p>
  
  <pre><code>&lt;script&gt;
  $(document).ready(function () {
      $('#exportFromDB').click(function () {
          $.ajax({
              url: "",
              type: "post",
              headers: {'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')},
              data: {},
              success: function (response) {
                  var a = document.createElement("a");
                  a.href = response.file;
                  a.download = response.name;
              }
          })
      })
  })
  </code></pre>
  
  <p></p>
  
  <p><strong>TitleController.php:</strong></p>
  
  <pre><code>    $dataExport['Oversea'] = $dataOversea;
      $this-&gt;titleRepository-&gt;export('csv', $properties, $dataExport);
  </code></pre>
  
  <p><strong>TitleRepository.php</strong></p>
  
  <pre><code>public function export($type, $properties, $data)
  {
      if (in_array($type, self::EXPORT_TYPE)) {
          try {
              return Excel::create($properties['_title'], function ($excel) use ($data, $properties) {
  
                  $excel-&gt;setTitle($properties['_title']);
                  $excel-&gt;setCreator($properties['_creator'])
                      -&gt;setCompany($properties['_company']);
                  $excel-&gt;setDescription($properties['_description']);
  
                  $excel-&gt;sheet('Sheet', function ($sheet) use ($data) {
                      foreach ($data as $item) {
                          $sheet-&gt;fromArray($item);
                      }
                  });
              })-&gt;export($type);
          } catch (Exception $error) {
              throw $error;
          }
      }
  }
  </code></pre>
  
  <p>How can I fix them ? Thank !</p>