Downloading file though AJAX POST

后端 未结 3 1258
伪装坚强ぢ
伪装坚强ぢ 2020-12-20 05:56

I\'m trying to provide a simple download using AJAX POST request. A user clicks a and the download begins (or a download dialog shows up, depending

3条回答
  •  攒了一身酷
    2020-12-20 06:47

    I don't think its possible using ajax, I had the same issue and the download was not triggered. My solution was using only PHP:

    1. Create a new file when the page is loaded, on the background. This will be stored in a server location.

      $out = fopen('filename', 'w+');
      //write data in file
      fputcsv($out, some csv values );
      
    2. have a link to the client to download it

      Export Data to CSV file
      

    And depending on how often this is done, you must clean-up the downloads regularly to not fill the server.

提交回复
热议问题