当我在PostMan上调用此函数时,它会下载PDF,但当我从页面上调用它时,它不会下载,但请求已经到达。我希望它能够下载。
,generateFarmerPDF:function (id) {
this.farmerId = id
var data = new FormData()
data.append('function','generateFarmerPDF')
data.append('farmerId',this.farmerId )
axios.post(this.url,data)
.then( function (response ) {
}.bind(this)).catch(function (error) {
})
}
这里是API代码
if ($function == "generateFarmerPDF") {
$farmerId = $_POST['farmerId'];
$result = DB::instance()->executeSQL("SELECT * FROM `milk_production` WHERE `farmerId` ='$farmerId'");
$header = DB::instance()->executeSQL("SELECT `COLUMN_NAME`
FROM `INFORMATION_SCHEMA`.`COLUMNS`
WHERE `TABLE_SCHEMA`='blog_samples'
AND `TABLE_NAME`='milk_production'");
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial', 'B', 5);
foreach ($header as $heading) {
foreach ($heading as $column_heading)
$pdf->Cell(20, 6, $column_heading, 1);
}
foreach ($result as $row) {
$pdf->SetFont('Arial', '', 5);
$pdf->Ln();
foreach ($row as $column)
$pdf->Cell(20, 6, $column, 1);
}
$pdf->Output();
}
这就是我所称呼它的方式。
<button v-on:click="generateFarmerPDF(milkvolume.farmerId)">Report</button></td>