Good afternoon I'm passing via ajax some fields from my modal to a PHP function. This way, I run the query below in the PHP function to generate an Excel spreadsheet. the problem is that: I even get the values via POST in PHP but it gives error in the creation of the EXCEL worksheet. If I put the fixed value in the variable, the spreadsheet is created without problems. Where am I going wrong in this case?
function exp_excel()
{
var url = "<?php echo site_url('ExpExcel/exportExcel')?>";
$.ajax({
url : url,
type: "POST",
data: $('#form_1').serialize(),
dataType: "HTML",
success: function(data)
{
window.location = url;
$('#modal_excel').modal('hide');
},
error: function (request, status, erro) {
},
});
}
public function exportExcel()
{
//$gestor = $_POST["NomeGestor"]; -> assim nao funciona
//$qtdDias = $_POST["qtdDias"];
$gestor = "Francisco Jose"; -> assim funciona normal
$qtdDias = "3";
try{
$query = "SELECT * FROM tbl_dpo_1 WHERE
gestor LIKE '{$gestor}' AND (data_oper >= DATE_SUB(CURDATE() ,INTERVAL {$qtdDias} DAY)
AND data_oper <= CURRENT_DATE()) AND (operacao LIKE 'UPD_REG' OR operacao LIKE 'NEW_REG')";
$resultado = mysql_query($query);
//CRIA O OBJETO PARA EXPORTAR PARA O EXCEL
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$data = date('dmy');
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="DPO-Consolidado_'. $data .".xlsx");
header('Cache-Control: max-age=0');
$objWriter->save('php://output');
}