$.ajax({
url:"download.php",
method:"post",
data:{fileName:fileName},
success:function(e){
alert(e);
}
})
Your code is sending back the bytes of the file you want to download. You are then trying to display those bytes in an
alert
, which can only display text. That is why you are getting a message full of gibberish - that's Javascript trying its best to interpret the bytes as a string.
You can't use an AJAX request to download a file. Since you require a
POST
request, you'll need to create a hidden
<form>
pointing to your download page, and submit it from your code.
Alternatively, change your
download.php
code to work with a
GET
request, add the filename to the query-string on your link, and add
the download
attribute[
^] to the link.