Skip to main content
added 8 characters in body
Source Link
Shehabic
  • 6.9k
  • 11
  • 56
  • 95

simply using jQuery and ajax: JFYI: input size limit is a server setting, it doesn't matter you're using ajax or form with input html:

$<form id="downloaderForm" action="downloadCsv.ajax({ php" method="post"> <intput type="hidden" name="json" url:id="jsonData" "/path/to> </php_script.php",form> 

JQuery

 $("#jsonData").val(yourData);  $("#downloaderForm").submit(); 

or JS

document.getElementById("jsonData").value = yourData; document.getElementById("downloaderForm").submit(); 

PHP

header("Content-type: "POST",text/csv");  dataheader("Content-Disposition: "jsonData=" +attachment; stringifiedArray,filename=json-cconverted-to-csv.csv");  successheader("Pragma: function(responseno-cache") {;  if header(response ==="Expires: "some-value"0") {;  echo $csvData; // redirect the user to dowload the file } } Your CSV  });Data 

simply using jQuery and ajax: JFYI: input size limit is a server setting, it doesn't matter you're using ajax or form with input

$.ajax({  url: "/path/to/php_script.php", type: "POST",  data: "jsonData=" + stringifiedArray,  success: function(response) {  if (response === "some-value") {   // redirect the user to dowload the file } }   }); 

simply using jQuery and ajax: JFYI: input size limit is a server setting, it doesn't matter you're using ajax or form with input html:

<form id="downloaderForm" action="downloadCsv.php" method="post"> <intput type="hidden" name="json" id="jsonData" /> </form> 

JQuery

 $("#jsonData").val(yourData);  $("#downloaderForm").submit(); 

or JS

document.getElementById("jsonData").value = yourData; document.getElementById("downloaderForm").submit(); 

PHP

header("Content-type: text/csv"); header("Content-Disposition: attachment; filename=json-cconverted-to-csv.csv"); header("Pragma: no-cache"); header("Expires: 0"); echo $csvData; // Your CSV Data 
Source Link
Shehabic
  • 6.9k
  • 11
  • 56
  • 95

simply using jQuery and ajax: JFYI: input size limit is a server setting, it doesn't matter you're using ajax or form with input

$.ajax({ url: "/path/to/php_script.php", type: "POST", data: "jsonData=" + stringifiedArray, success: function(response) { if (response === "some-value") { // redirect the user to dowload the file } } });