i want to download a file using ajax via post request using jQuery.
here is the PHP code i am using.
if (file_exists($file)) {
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=$file");
header("Content-Type: application/zip");
header("Content-Transfer-Encoding: binary");
readfile($file);
}
and this is the jQuery.
$('button.erp_ci_download').click(function(){
var formData = $('form#erp_customerinvoice').serialize();
$.ajax({
type: 'POST',
url: "App/Ajax/Excel/Download.php",
data: formData
});
});
is it not possible to download it this way? i tried googling and some suggested it is the same way i am doing it. but in my console it shows some garbage values as response.
where am i going wrong?
thank you..