mardi 5 mars 2019

Laravel 5 : Ajax response download not working

Tried below code:

$headers = [
        'Cache-Control'       => 'must-revalidate, post-check=0, pre-check=0',
        'Content-type'        => 'text/csv',
        'Content-Disposition' => 'attachment; filename=list.csv',
        'Expires'             => '0',
        'Pragma'              => 'public'   
      ];

    $list = List::all()->toArray();

    # add headers for each column in the CSV download
    array_unshift($list, array_keys($list[0]));
    $FH = fopen(storage_path('list.csv'),'w');
    foreach ($list as $row) { 
        fputcsv($FH, $row);
    }
    fclose($FH);

    $path = storage_path('list.csv');

    return response()->download($path, 'list.csv', $headers);

Below will out put in inspect element network call

enter image description here

I have got the same issue in Stack overflow but not working for me. Exporting CSV response laravel 5.5 and download as csv file

Can have any idea regarding this what I have missing in here?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire