Php 无法在jquery ajax调用中获取pdf
我正在使用生成pdf文件。我可以通过超链接获取pdf文件。但无法点击按钮 这是代码 createReport.phpPhp 无法在jquery ajax调用中获取pdf,php,jquery,ajax,pdf,Php,Jquery,Ajax,Pdf,我正在使用生成pdf文件。我可以通过超链接获取pdf文件。但无法点击按钮 这是代码 createReport.php <?php //$operation = $_POST['action']; require('fpdf.php'); $pdf = new FPDF(); $pdf->AddPage(); $pdf->SetFont('Arial', 'B', 16); $pdf->Cell(40, 10, 'Hello World!'); $pdf->Outpu
<?php
//$operation = $_POST['action'];
require('fpdf.php');
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial', 'B', 16);
$pdf->Cell(40, 10, 'Hello World!');
$pdf->Output('t','D');
?>
index.html
<html>
<head>
<meta charset="UTF-8">
<title>Demo Report</title>
<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
<script>
$(document).ready(function() {
$('#showreport').click(function() {
$.post("createReport.php", {suggest: "txt"}, function(result) {
alert("got it");
});
});
});
</script>
</head>
<body>
<input type="button" id="showreport" value="Show Report"/>
<a href="createReport.php">click me</a>
</body>
</html>
演示报告
$(文档).ready(函数(){
$('#showreport')。单击(函数(){
$.post(“createReport.php”,{suggest:'txt},函数(结果){
警惕(“明白了”);
});
});
});
单击“单击我”链接,我可以看到报告为hello World。但按一下按钮,什么也没发生。我需要发送的数据,如从和到目前为止,我想从数据库生成报告
请告诉我哪里出了问题
感谢您的回复
谢谢。只要换新的就行了
alert("got it");
用下面的代码
var uri = 'data:application/pdf;charset=UTF-8,' + encodeURIComponent(data); window.open(uri, 'tiketi.pdf');
如果需要传入from和todate,那么可以将这些变量放入AJAX请求中的数据对象中。我在代码中的任何地方都看不到该数据的字段,因此无法进一步提供帮助..不,这是我的要求。但出于测试目的,我只发送了一些数据。如果我能成功发送“建议”参数。我可以继续。好的,首先如果你收到报告,你应该使用GET not POST。其次,您是否检查了控制台中的错误,跟踪了AJAX请求,并进行了任何类型的调试?我可以简单地假设,您没有收到预期的警报,这将指向一个失败的请求,这可能是因为许多原因,包括错误的URL、Javascript语法错误、PHP语法错误等等!!我只使用post。我收到了警报。