I have a php file like this:
<?php
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=\"my-data.csv\"");
$data = stripcslashes($_REQUEST['data']);
echo $data;
?>
I can post (proper formatted) data to it and it will return a csv file. I do that like this:
var data = $('table').toCSV('tbody > tr');
$('table').addEvent('click', function(){
new Request({
url: 'getCSV.php',
method: 'post'
}).send('data=' + data);
});
In Firebug I can see the request works and the response is ok. But the Download dialog does not pop up; how to fix that? Do I need different headers in the PHP file?
I changed the JS to this:
Which adds a nice download button to the table and as the browser follows a form submit, the download dialog pops up. Thanks for thinking with me.