follow below steps:
Step 1
msqXLS +='form style="display:inline" action="SaveToCSV.php" method="post" target="_blank" onsubmit="$(\'#datatodisplay\').val( $(\'\').append( $(\'#ReportTable\').eq(0).clone() ).html() )">';
msqXLS +='input_type="submit" value="Save as CSV">';
msqXLS +='
msqXLS +='Some header in csv vile, some header in csv file\n';
for (var i=0;i <>
msqXLS +=DataSource.getElementsByTagName('xxx')[i].firstChild.nodeValue+','+DataSource.getElementsByTagName('xx')[i].firstChild.nodeValue+'\n';
};
msqXLS +='"/>';
msqXLS +='
...
if require to print displayed data put content inside the printArea and call javacript "print()" to print it.Step 2
And than create and paste below code in php file name it "SaveToCSV.php"
Step 3
put all the file in htdocs, and then try call your ajax page from browser.
finally you will had csv file to download


