Php 使用jQuery AJAX和window.open的FPDF单击链接即可打开pdf
我有一个表单,从这个表单中,我使用jquery AJAX将值发布到FPDF以在服务器上存储pdf,然后我希望浏览器使用window.open(url,“_blank”),在一个新的选项卡中打开pdf。open(url,“_blank”),窗口打开,但pdf没有加载,我将永远保留旋转加载图标,在使用PHP函数读取url时也是_dir()它返回false。。但是文件在FTP客户端中,我可以下载并读取它 以下是表格的页面:Php 使用jQuery AJAX和window.open的FPDF单击链接即可打开pdf,php,fpdf,Php,Fpdf,我有一个表单,从这个表单中,我使用jquery AJAX将值发布到FPDF以在服务器上存储pdf,然后我希望浏览器使用window.open(url,“_blank”),在一个新的选项卡中打开pdf。open(url,“_blank”),窗口打开,但pdf没有加载,我将永远保留旋转加载图标,在使用PHP函数读取url时也是_dir()它返回false。。但是文件在FTP客户端中,我可以下载并读取它 以下是表格的页面: jQuery(document).ready(function(){
jQuery(document).ready(function(){
jQuery('.getPdf').live('click', function(event){
event.preventDefault();
var catId = jQuery(this).attr("id");
jQuery('.removePost').remove();
jQuery.ajax({
type: "POST",
url: "/wp-content/themes/weld-wide/ajax-post-to-pdf.php",
data:jQuery('#form'+catId).serialize(),
success:function(url){
window.open(url, '_blank');
},
});
});
});
以下是处理pdf创建的ajax文件:
require ('fpdf/fpdf.php');//including the main class
//create FPDF object
$pdf=new FPDF();
//set document properties
$pdf->SetAuthor('Weld Wide');
$pdf->SetTitle('Weld Wide Metal Work');
//set text colour for the entire document
$pdf->SetTextColor(50,60,100);
//set up a page
$pdf->AddPage('P');
$pdf->SetDisplayMode(real,'default');
//insert an image and make it a link
//$pdf->Image('../images/logo.png',10,20,33,0,' ','http://www.weld-wide.co.uk/');
//display the title with a border around it
$pdf->SetXY(65,20);
//$pdf->SetDrawColor(50,60,100);
//$pdf->Cell(100,10,'FPDF Tutorial',1,0,'C',0);
$pdf->Image('images/logo.png');
//Set x and y position for the main text, reduce font size and write content
$pdf->SetXY (10,50);
$pdf->SetFontSize(10);
$pdf->SetFont('Helvetica','B',12);
$pdf->Write(10, "Listed below are your selections for your metal work:\n");
$pdf->SetFont('Helvetica','',10);
foreach($_POST as $k => $v) {
$pdf->Multicell(0,7,str_replace('_',' ',$k)." : ".str_replace('-',' ',$v)."\n");
}
$rand = rand(1,1000000);
//Output the document F means save to server, D for download window popup
$pdf->Output('fpdf/temp_pdf/weld-wide-gate'.$rand.'.pdf','F');
$url = "http://www.".$_SERVER["HTTP_HOST"]."/wp-content/themes/weld-wide/"."fpdf/temp_pdf/weld-wide-gate".$rand.".pdf";
echo $url;
你不需要这条线
$url = "http://www.".$_SERVER["HTTP_HOST"]."/wp-content/themes/weld-wide/"."fpdf/temp_pdf/weld-wide-gate".$rand.".pdf";
echo $url;
只需删除它并将其添加到最后一行
$pdf->Output('fpdf/temp_pdf/weld-wide-gate'.$rand.'.pdf','I');
或
看起来是这样的
$pdf->Output('fpdf/temp_pdf/weld-wide-gate'.$rand.'.pdf','F');
$pdf->Output('fpdf/temp_pdf/weld-wide-gate'.$rand.'.pdf','I');
或
希望这将对您有所帮助您是否检查了脚本的响应?访问权限呢?那个目录可以从外面访问吗?
$pdf->Output('fpdf/temp_pdf/weld-wide-gate'.$rand.'.pdf','F');
$pdf->Output('fpdf/temp_pdf/weld-wide-gate'.$rand.'.pdf','I');
$pdf->Output('fpdf/temp_pdf/weld-wide-gate'.$rand.'.pdf','F');
$pdf->Output('weld-wide-gate'.$rand.'.pdf','I');