I am posting a HTML table data as json to server side using jquery $.post for writing the whole table data to csv file. but this is not outputting csv as downloadable for user.
I want to pop up the csv file (which normally happens when we download a file. you know the SAVE or OPEN box for csv)
Client side code
//selectedData is having the data as json
$.post('ajax/csv_download.php', {
selectedData: JSON.stringify(selectedData)
}, function(html){ });
Server Side code
global $fh;
$fh = @fopen( 'php://output', 'w' );
$post_data = json_decode($_POST['selectedData']);
foreach ($post_data as $arr)
{
$val1 = $arr->val1 ;
$val2 = $arr->val2 ;
$val3 = $arr->val3 ;
$val4 = $arr->val4 ;
$val5 = $arr->val5 ;
$out = array($val1,$val2,$val3,$val4,$val5);
fputcsv($fh, $out);
}