Hi to all, i'm new there and i have a big problem, i hope find answer here.
So i want to generate xsl file from database and download without reload page.
So this is my controller:
PHP Code:
public function export()
{
$this->load->library("excel");
$rowscount = $this->Public->Count();
$object = new PHPExcel();
$object->setActiveSheetIndex(0);
$table_columns = array("Name");
$column = 0;
foreach($table_columns as $field)
{
$object->getActiveSheet()->setCellValueByColumnAndRow($column, 1, $field);
$column++;
}
$users = $this->Public->export();
$excel_row = 2;
foreach($users as $row)
{
$object->getActiveSheet()->setCellValueByColumnAndRow(0, $excel_row, $row->username);
$excel_row++;
}
$object_writer = PHPExcel_IOFactory::createWriter($object, 'Excel5');
header("Content-Type: application/vnd.ms-excel");
header("Content-Disposition: attachment;filename=Export.xls");
$object_writer->save('php://output');
}
This is form in view:
PHP Code:
<form role="form" action="<?php echo site_url('admin/export')?>" method="post">
<button class="btn btn-warning">Export</button>
</form>
This is work correct, but before download start the current page reloaded. I want with ajax make download form work without reload page.
Any hint how to do that?
Regards.