简体   繁体   中英

Download a file on button click and send value to the download file as parameter

Say I have a table on index page that changes dynamically when certain event is triggered.

Lets say I have another file: excel.php that generates excel sheet.

I want to run excel.php file(Which starts downloading an excel file), staying on index page for which I am using following jquery script.

$("#user_period_table_excel_btn").on("click", function(ev) {
    window.location.href = 'excel.cfm';
    ev.preventDefault();
    return false;
});

But the problem is I want to add the table htmls on index page to the excel.php file before downloading. In other word , I want to pass value in index page to the excel.php file.

I cannot use get method because the table is very very large.

Excel.php

$tab_content=/* I want to assign the table html code on index.html page*/
/*php script for generating $tab_content to excel sheet*/

Any help/suggestions is appreciated.

window.location.href = 'excel.php?param=123';

at the end of excel.php simply output excel file contents

header("Content-Disposition: attachment; filename=\"excel.xls");
header("Content-Type: application/force-download");
readfile('excel.xls')
die();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM