$(".getmydeal").click(function(){
var dealid = $(this).data("deal");
if(dealid != ""){
$.ajax({
type : "POST",
url : "ajax-download-deal.php",
data : {dealid:dealid},
success : function(response) {
//Some action to perform
}
});
}
});
单击getmydeal
时调用简单的ajax。现在问题是我需要在验证用户是否登录和订阅后下载pdf。所以我使用php如下
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_SESSION['portaluser'])) {
$mymobile = mysqli_real_escape_string($conn,$_POST['dealid']);
//This is my code for downloading pdf
$file = "http://www.pdf995.com/samples/pdf.pdf";
header('Content-Type: application/pdf');
header("Content-Disposition: attachment; filename=\"$file\"");
readfile($file);
}else{
//User Must Login First
}
但是服务器没有下载该文件。所以可以使用ajax在php文件上下载pdf。