i am having problem in downloading a CSV file using codeigniter, i want when user press the export button file should start downloading but what happens is response is generated in ajax called function as shown in screen shot. I know i am missing some thing small but i can not get my head straight over it what to do.
AJAX RESPONSE SHOWN IN FIREFOX CONSOLE
HTML BUTTON
<button id="exportData" name="exportData" class="btn btn-primary btn-lg" >Download CSV</button>
AJAX CALL
$(document).on('click','#exportData',function(e){
e.preventDefault();
var jawad = $( ".jawad" ).serialize();
$.ajax({
url : '<?=base_url();?>command/getReport',
type : 'POST',
data : {str:jawad,procName:$('#procName').val()}
});
});
PHP FUNCTION:
function getReport()
{
//removing above lines as not necessary
$jawad = $query->result_array();
//pass it to db utility function
$new_report = $this->dbutil->csv_from_result($query);
$this->load->helper('download');
force_download('csv_file.csv', $new_report);
}