cant get values printed in to a file
- by user1371896
Iam trying to pass the value stored in the variable fieldCSV to file data.csv...Ive used javascript and php to do this.. I have triggered an ajax request when a value is stored in to the variable fieldCSV, bt this is nt working as the file that gets downloaded prints the php error inside it instead of csv..
$.ajax({
type: "POST",
url: "/test/fileDownload.php",
data: {
name: fieldCSV},
});
<?php
$name = $_POST["name"];
header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename=data.csv');
$output = fopen('php://output', 'w');
fputcsv($output, $name);
?>
What am I doing wrong?