脚本宝典收集整理的这篇文章主要介绍了php – 从ajax post下载pdf,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
$('#downloadPdf').click(function() { VAR id = $('#fileid').val(); $.ajax({ tyPE: "POST",url: "includes/download_pdf.PHP",data: 'file_id=' + id,complete: function(data) { $('#pdf_results').htML(data.responseText); } }); });
<?PHP $file_name = $_POST['file_id']; // We'll be outputting a PDF header('Content-type: application/pdf'); // IT will be called downloaded.pdf header('Content-Disposition: attachment; filename="'.$file_name.'.pdf"'); // The PDF source is in original.pdf readfile('/var/www/vhosts/domain.nl/PRivate/'.$file_name.'.pdf'); ?>
当我使用这段代码时,我会在#pdf_results中看到所有奇怪的迹象.我想将PDF保存到我的电脑,但这不起作用.
提前致谢!
$(function(){ $('#downloadPdf').click(function(){ var id = $('#fileId').val(); window.open(location.protocol + '//' + location.hostname + '/includes/download_pdf.PHP?file_id=' + id); return false; }); });
干杯!
以上是脚本宝典为你收集整理的php – 从ajax post下载pdf全部内容,希望文章能够帮你解决php – 从ajax post下载pdf所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。