Jquery:加载PDF时显示对话框(例如,使用jquery.fileDownload.js)

时间:2012-12-31 10:14:41

标签: php jquery

在我的网站上,我有一个php文件,它使用mpdf-plugin通过在MYSQL数据库上进行查询来创建pdf文件。

基本网址:pdf_report.php?VARa = b& VARb = c。 (VARa和VARb用作GET变量来对数据库进行查询。)

不是我真正的问题:我想显示在生成PDF时显示的加载对话框。完成后,加载对话框将消失并下载PDF文件(或在浏览器中显示)。 为了达到这个目的,我想我可以使用examples来使用“jquery.fileDownload”文件。但由于我是Jquery的初学者,我无法找到让它工作的方法。

到目前为止我所得到的是(完全遵循这些例子):

<?php 
header('Set-Cookie: fileDownload=true');
header("Content-type: text/pdf");
header('Content-Disposition: attachment; filename="report_b_c.pdf"');
//b and c are the values of the variables VARa and VARb
?>

<html>
<head>
<title>PDF Wait dialog</title>
<link href="css/jquery-ui.css" rel="stylesheet" type="text/css"/>
<script src="js/jquery-ui.js" type="text/javascript"></script>
<script src="js/jquery-1.8.3.js" type="text/javascript"></script>
<script src="js/jquery.fileDownload.js" type="text/javascript"></script>
enter code here
</head>
<body>
<script>
$(function () {
$(document).on("click", "a.fileDownloadCustomRichExperience", function () {

    var $preparingFileModal = $("#preparing-file-modal");

    $preparingFileModal.dialog({ modal: true });

    $.fileDownload($(this).attr('href'), {
        successCallback: function (url) {

            $preparingFileModal.dialog('close');
        },
        failCallback: function (responseHtml, url) {

            $preparingFileModal.dialog('close');
            $("#error-modal").dialog({ modal: true });
        }
    });
    return false; //this is critical to stop the click event which will trigger a normal file download!
});
});
</script>
<div id="preparing-file-modal" title="Preparing report..." style="display: none;">
We are preparing your report, please wait...

<div class="ui-progressbar-value ui-corner-left ui-corner-right" style="width: 100%; height:22px; margin-top: 20px;"></div>
</div>

<div id="error-modal" title="Error" style="display: none;">
There was a problem generating your report, please try again.
</div>
<a class="fileDownloadCustomRichExperience" href="pdf_logboek_report.php?VARa=b&VARb=c">Report.pdf</a>
</body>
</html>

[编辑] 运行此php文件时,不会显示任何错误。有时0.5秒会显示一个对话框并下载pdf文件。文件名:logboek_report_.pdf(这不是预期的文件,内容为空!)

当我运行pdf_logboek_report.php?VARa = b&amp; VARb = c时,会创建并显示(或根据浏览器支持下载)预期的pdf文件。

[编辑] 我想加载的pdf通常需要30-60秒才能生成。

但遗憾的是,由于我(作为初学者)做错了什么,因此无法正常工作。或者是以我想要的方式实现对话的一种更简单的方法吗?!

请帮帮我!

0 个答案:

没有答案