0

I have seen many examples but none of them is resolving my issue. I generated cvs file in ajax post request ( I am not changing window.location.href). I want this file to auto download just like what happens after changing window.location.href. Currently i don't know solution.Kindly help me here is my code

$file_name="temp_".time().".csv";
$new_csv = fopen($file_name, 'w');
fputcsv($new_csv, $csv_data);
fclose($new_csv);
header("Content-type: application/csv; charset=utf-8");
header("Content-disposition: attachment; filename =\"" .$file_name. "\"");
readfile($file_name);
unlink($file_name);
exit;
$this->setLayout(false);
return sfView::NONE;
Saad Ahmed
  • 43
  • 4
  • this is NOT possible via ajax. but have a look at answers here : http://stackoverflow.com/questions/4545311/download-a-file-by-jquery-ajax – Alexis Peters Apr 04 '16 at 06:12
  • can you post your javascript code, if you're not redirecting this is were this would happen. – gmfm Apr 04 '16 at 06:13
  • Basically i have a very long data array which i can't send in url so thats why i am using post request. But if you know to access data after changing window.location then kindly let me know.thanks – Saad Ahmed Apr 04 '16 at 06:15
  • $.post("/d/" + d.getTime(), postdata.serialize(), function(){ $("#loading").hide(); $("#loading-overlay").hide(); – Saad Ahmed Apr 04 '16 at 06:16
  • here is javascript – Saad Ahmed Apr 04 '16 at 06:16

0 Answers0