我通過jQuery將用戶數據發送到TCPDF,但它不顯示從PDF文件中接收到的來自jQuery的任何值。TCPDF沒有通過jQuery捕獲PHP變量
我甚至試圖捕獲會話變量中的值,但它仍然不顯示。我哪裏錯了?
HTML:
<div id="p">
FOO
<input type="text" id="nop" />
</div>
<div id="e_table">
<table>
<thead>
<th><h3>ABC</h3></th>
<th><h3>PQR</h3></th>
<th><h3>XYS</h3></th>
</thead>
<tbody>
<tr>
<td>Staff</td>
<td><input type="text" id="as" /></td>
<td><label id="las">label</label></td>
</tr>
<tr>
<td>Office</td>
<td><input type="text" id="bo"/></td>
<td><label id="lbo">label</label></td>
</tr>
<tr>
<td>Administrative</td>
<td><input type="text" id="mca" /></td>
<td><label id="lmca">label</label></td>
</tr>
</tbody>
</table>
</div>
的jQuery:
$('#pdf').click(function() {
var nop = $('#nop').val();
var as = $('#as').val();
var las = $('#las').text();
var bo = $('#bo').val();
var lbo = $('#lbo').text();
var mca = $('#mca').val();
var lmca = $('#lmca').text();
var postData = {
"nop" : nop,
"as" : as,
"las" : las,
"bo" : bo,
"lbo" : lbo,
"mca" : mca,
"lmca" : lmca
};
$.ajax({
type: "POST",
url: "pdf.php",
data: postData,
success: function(data){
window.open("pdf.php");
}
});
});
TCPDF pdf.php:
<?php
session_start();
//============================================================+
// Author: Nicola Asuni
//
// (c) Copyright:
// Nicola Asuni
// Tecnick.com s.r.l.
// Via Della Pace, 11
// 09044 Quartucciu (CA)
// ITALY
// www.tecnick.com
// [email protected]
//============================================================+
/**
* @author Nicola Asuni
* @since 2009-03-20
*/
require_once('tcpdf/config/lang/eng.php');
require_once('tcpdf/tcpdf.php');
// Extend the TCPDF class to create custom Header and Footer
class MYPDF extends TCPDF {
// Page footer
public function Footer() {
// Position at 15 mm from bottom
$this->SetY(-15);
// Set font
$this->SetFont('helvetica', 'B', 8);
$this->SetTextColor(247, 147, 29);
$this->Cell(0, 10, 'ABC', 0, false, 'C', 0, '', 0, false, 'T', 'M');
}
}
// create new PDF document
$pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('ABC');
$pdf->SetTitle('ABC');
$pdf->SetSubject('ABC');
$pdf->SetKeywords('ABC');
// set default header data
$pdf->SetHeaderData(false);
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
//set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, 5, PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
//set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
//set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
//set some language-dependent strings
$pdf->setLanguageArray($l);
// ---------------------------------------------------------
// add a page
$pdf->AddPage();
$pdf->SetFont('helvetica', '', 8);
// -----------------------------------------------------------------------------
//request parameters
$nop = strip_tags($_POST['nop']);
$_SESSION['nop'] = $nop;
$nop = $_SESSION['nop'];
$as = strip_tags($_POST['as']);
$las = strip_tags($_POST['las']);
$bo = strip_tags($_POST['bo']);
$lbo = strip_tags($_POST['lbo']);
$mca = strip_tags($_POST['mca']);
$lmca = strip_tags($_POST['lmca']);
$tbl = <<<EOF
<div>
<table border="0" cellpadding="5" cellspacing="2">
<tr>
<td>FOO</td>
<td>$nop</td>
</tr>
</tbody>
</table>
</div>
<hr>
<div>
<table border="0" cellpadding="5" cellspacing="2">
<thead>
<tr>
<th><h3>ABC</h3></th>
<th><h3>PQR</h3></th>
<th><h3>XYS</h3></th>
</tr>
</thead>
<tbody>
<tr>
<td>Staff</td>
<td>$as</td>
<td>$las</td>
</tr>
<tr>
<td>Office</td>
<td></td>
<td></td>
</tr>
<tr>
<td>Administrative</td>
<td></td>
<td></td>
</tr>
</tbody>
</table>
</div>
</div>
EOF;
$pdf->writeHTML($tbl, true, false, false, false, '');
$txt = $nop . 'This';
// print a block of text using Write()
$pdf->Write($h=0, $txt, $link='', $fill=0, $align='C', $ln=true, $stretch=0, $firstline=false, $firstblock=false, $maxh=0);
// -----------------------------------------------------------------------------
//Close and output PDF document
$pdf->Output('ABC.pdf', 'I');
//============================================================+
// END OF FILE
//============================================================+
感謝您的幫助打開。這工作。我只想知道我是否可以隱藏url字符串中的參數? – input 2012-04-09 20:18:00
@input不好意思,不要拿。取決於你想隱藏的原因,但是很容易查看發送到的發佈值 – trembon 2012-04-10 06:43:32