Laravel 5:Ajax响应下载不起作用

时间:2019-03-05 10:19:49

标签: ajax laravel-5 laravel-4 laravel-5.2 laravel-5.1

尝试以下代码:

$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);

以下将放入检查元素网络调用

enter image description here

我在堆栈溢出中遇到了同样的问题,但对我却不起作用。 Exporting CSV response laravel 5.5 and download as csv file

对此有什么想法吗?

0 个答案:

没有答案