0

from this option of my drop down menu im trying to call javascript function gen(); my html table is 'horse_trainings' which is converted to cvs format; but it didnot download where as when i checked code on the internet it all headers were the same procedures everything matched but it didnt work.

<li><a href="#" onclick="gen();">Export In Excel</a></li>

This is my script:

<script type="text/javascript" src="http://www.kunalbabre.com/projects/table2CSV.js"> </script>
<script>
function gen()
{
var csv_value=$('#horse_trainings').table2CSV({delivery:'value'});
 $.ajax({
            type:"POST",
            url:"trainingxls.php",
                    datatype:"csv/text",
            data:"func=text&data="+csv_value+"",    
        }).done(function(t){
            alert(t);
            });
}
</script>

my trainingxls.php file:

<?php
if(isset($_POST["func"])){
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=\"my-data.csv\"");
$d=stripcslashes($_REQUEST['data']);
//echo $_POST['data'];
echo $d;
}
?>

problem: Its not downloading the cvs file on click.

jenny
  • 11
  • 3
  • You can not download files with AJAX. See this answer: http://stackoverflow.com/questions/4545311/download-a-file-by-jquery-ajax – Pono Jun 27 '13 at 07:20
  • You may get your answer from this link **http://stackoverflow.com/questions/4545311/download-a-file-by-jquery-ajax** – pixelbyaj Jun 27 '13 at 07:32
  • dear don't use ajax just create csv or path of csv file then direct hit from url and pass header this file thanks – Asif Jun 27 '13 at 07:46

0 Answers0