Through post
method in jquery I tried to download a pdf but it doesn't work. File is not getting downloaded. where am I doing wrong?
main.php
<html>
<head>
<script src="http://code.jquery.com/jquery-1.9.1.js" type="text/javascript"></script>
</head>
<body>
<script>
function downloadpdf(){
alert("working");
$.post('download.php',{pdf:'Intro.pdf'},function(data){if(data=="y"){alert("Downloaded");}});
}
</script>
<button onclick="downloadpdf();">download</button>
</body>
</html>
download.php
<?php
if(isset($_POST['pdf'])){
$bbpdf=$_POST['pdf'];
header("Content-disposition: attachment; filename=$bbpdf");
header("Content-type: application/pdf");
header('Content-Length: ' . filesize($bbpdf));
readfile($bbpdf);
echo "y";
}