I'm trying to create button to download a file with an ajax call but the ajax call get the file content on the response but doesn't create the download,(the download file is correct,the download is created if you type the url)
<div class="col-md-3" id="export-btn">
<button class=" btn btn-success">Exportar</button>
</div>
the ajax call
$('#export-btn').on('click',function(){
$.ajax({
url: "download.php",
method:'get'
}).done(function(response){
console.log(response);
});
});
and this is the download file,that works correct
<?php
header('Pragma: public');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Cache-Control: private', false);
header('Content-Type: application/octet-stream');
header('Content-Transfer-Encoding: binary');
header('Content-Disposition: attachment; filename="cataleg_peticions.csv"');
$url = "cataleg_peticions.csv";
readfile($url);
exit();
?>