Download a file with an ajax call

前端 未结 5 393
面向向阳花
面向向阳花 2021-01-13 11:25

I am using PHPExcel to read an excel template, populate the data, and ask the user to download the file.

generate_excel.php

$objPHPExcel = PHPExcel_I         


        
5条回答
  •  情话喂你
    2021-01-13 11:57

    You can try this way:

    1. Send a Jquery AJAX POST request with the data that is to be used to generate excel report, and store that data in a session variable. Return an arbitrary string like 'success' as the response.
    2. If the output of the above AJAX call is 'success', then do a GET request to another URL in your application, that reads the data from session (stored in the first step, else throw an error), prepares an excel file out of that data, and forces the download of that excel file to the browser.

提交回复
热议问题