title: Why is the return()->response not working after the AJAX call, Laravel, JQuery?
body: <p>The JQuery(AJAX call):</p>
  <pre><code>$('#frm').validate({
    rules: {
      date1: {
        required: true,
      },
      date2: {
        required: true,
      },  
    },
  
    submitHandler: function(form) {
              let formD = new FormData(form);
      
      //formD.append(Report_id, $('#inp_2').val());
      
      $.ajax({            
        url: form.action,
        type: form.method,
        data: formD,
        processData: false,
        contentType: false,
        cache: false,
        success:function(data)
        {
          toastr.success(data);
          
        }, 
        error:'', 
      })
    }
  });
  </code></pre>
  <p>Controller:</p>
  <pre><code>public function product_list_report(Request $request)
  {
      $validator = Validator::make($request-&gt;all(),[
          &quot;date1&quot; =&gt; 'required',
          &quot;date2&quot; =&gt; 'required',
      ]);
  
      if($validator-&gt;fails()){return dd(&quot;Errored&quot;);}
      $f = time().'_'.'mybin_report.csv';
      $headers = array(
          'Content-Type' =&gt; 'application/vnd.ms-excel; charset=utf-8',
          'Cache-Control' =&gt; 'must-revalidate, post-check=0, pre-check=0',
          'Content-Disposition' =&gt; 'attachment; filename='.$f,
          'Expires' =&gt; '0',
          'Pragma' =&gt; 'public',
      );
      $filename =  public_path(&quot;files/&quot;.$f);
      if(isset($request-&gt;inp_2))
      {
          $data = DB::table('products')
          -&gt;select('products.id as product_id', 'products.name as product_name', 'products.format', 'products.code as product_code', 'products.description', 'products.created_at')
          -&gt;orderBy('products.created_at', 'DESC')
          -&gt;get();
          $columns = array('Product_id', 'Name', 'Format', 'Code', 'Description', 'Created On');
  
          if (!File::exists(public_path().&quot;/files&quot;)) {
              File::makeDirectory(public_path() . &quot;/files&quot;);
          }
          //creating the download file
          $file = fopen('php://output', 'w');
          fputcsv($file, $columns);
  
          $handle = fopen($filename, 'w');
          foreach ($data as $dt) {
              fputcsv($handle, [$dt-&gt;product_id, $dt-&gt;product_name, $dt-&gt;format, $dt-&gt;product_code, $dt-&gt;description, $dt-&gt;created_at,]);    
          }
          $response = array(
              'status' =&gt; 'success',
              'response_code' =&gt; 200,
              'msg' =&gt; 'Successfully created',
          );
      }
      echo json_encode($response);
      fclose($handle);
      return response()-&gt;download($filename, $f, $headers);
  }
  </code></pre>
  <p>The following is th jquery toastr response which means the code is already done with the success part of the ajax call
  <a href="https://i.stack.imgur.com/j4wds.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/j4wds.png" alt="enter image description here" /></a></p>
  <p>then it comes back to the controller an when it executes <code>return response()-&gt;download($filename, $f, $headers);</code> the file should get downloaded which is not happening, without the AJAX call the file was being downloaded and I can't figure out why it ain't working.</p>
  <p>Any help will be appreciated.</p>