This is the HTML:
<button name="download">Download</button>
I want users to download a file when they click this button. For that, I'm using the following Ajax request:
$parent.find('button[name=download]').click(function () {
$.ajax({
url: "download.php",
sucess: function(data, status, jqXHR){
$console.text('Download efetuado');
},
error:function(xhr, status, error){
$console.text(xhr.responseText);
}
});
});
Where download.php is:
if (file_exists($myFile)){
header ("Content-Type: application/json");
header ("Content-Disposition: attachment; filename=$fileName");
header("Content-Length: " . filesize("$myFile"));
$fp = fopen("$myFile", "r");
fpassthru($fp);
} else {
echo "no file exists";
};
This isn't outputing anything and no file is downloaded. I know the PHP script is working and is being called.