I am making a link, which when the user clicks on it should generate an xls file. The link has the date-attributes and should pass these attributes to the page.php and generate the xls. I tried jquery and it is not working, does it have any other way?
<a href="#" id="xls" data-unidade="203" data-tema="1">
Gerar XLS
</a>
The jquery
$(document).ready(function() {
$('#xls').click(function(event) {
event.preventDefault();
$.ajax({
type: 'POST',
url : 'produto/exportXls',
data: {
'tema_id' : $(this).data('tema'),
'unidade_id' : $(this).data('unidade')
}
});
});
});
The php that creates the table to generate the xls
$html = '<table><tr>';
$html .= '<td colspan="3">Planilha teste</tr>';
$html .= '</tr>';
$html .= '<tr><td><b>Coluna 1</b></td><td><b>Coluna 2</b></td><td><b>Coluna 3</b></td></tr>';
$html .= '<tr><td>L1C1</td><td>L1C2</td><td>L1C3</td></tr>';
$html .= '<tr><td>L2C1</td><td>L2C2</td><td>L2C3</td></tr>';
$html .= '<tr><td>L3C1</td><td>L3C2</td><td>L3C3</td></tr>';
$html .= '</table>';
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D,d M YH:i:s") . " GMT");
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
header("Content-type: application/x-msexcel");
header("Content-Disposition: attachment; filename=arquivo.xls" );
header("Content-Description: PHP Generated Data" );
// Envia o conteúdo do arquivo
echo $html;
But it's not rolling ...