https://stackoverflow.com/questions/27701981/phpexcel-download-using-ajax-call
$objWriter = new PHPExcel_Writer_Excel5($objPHPExcel);
ob_start();
$objWriter->save("php://output");
$xlsData = ob_get_contents();
ob_end_clean();
$response = array(
'op' => 'ok',
'file' => "data:application/vnd.ms-excel;base64,".base64_encode($xlsData)
);
die(json_encode($response));
$.ajax({
type:'POST',
url:"MY_URL.php",
data: {},
dataType:'json'
}).done(function(data){
var $a = $("<a>");
$a.attr("href",data.file);
$("body").append($a);
$a.attr("download","file.xls");
$a[0].click();
$a.remove();
});
No comments:
Post a Comment