douwen1213 2012-08-13 16:22
浏览 44

PHP重定向到pdf然后导航到另一个页面?

I am using php and an apache server. My application gathers data from the user, put's it in a database, then uses PDFLib to display the formatted data back to the user as a pdf. My problem is, I would like the pdf to display as a new page, this works. But, I also have a blank page left up with the URL containing the variables used to display the pdf. I would like this page to show a different summary page, in HTML, without the variables in the URL, but I don't know how to do that. In the code that follows, I am going to the summary page if the medical flag is false. What I would like is to go to BOTH pages if the medical flag is true. Is this possible?

    if($medical_flag)  {
        header("Location: {$_SERVER['PHP_SELF']}/./index.php?step=wc_pdf&id={$event_id}");      
    } else {
        header("Location: {$_SERVER['PHP_SELF']}?step=success&id={$event_id}");
    }
    exit;

OK, I understand how this is impossible, but I still haven't figured out how to solve the problem. I thought I could toss the opening of the PDF back at jQuery with something like this:

jQuery(document).ready(function ()
{
function display_pdf_page(data, textStatus) {
    var current_record = data || {};
      //somehow display the pdf now         
}

function show_pdf(eventid){
    jQuery.getJSON(
        './inc/get_current_record_data_json.php',
        {'id': eventid},
        display_pdf_page           
    );      
} 
    ...
    });

Then after I process the data in php "call" the above using:

   echo '<script type="text/javascript">'
        , 'show_pdf($event_id);'
        , '</script>';  

But that doesn't work either, php doesn't know where to find show_pdf. My lack of understanding of client/server side events is killing me here. Call be obtuse... I don't get it.

  • 写回答

2条回答 默认 最新

  • donglu5612 2012-08-13 16:35
    关注

    This solution will not work as designed.

    First, if you want to hide the data, you should switch to POST rather than GET. This way, the data is included in the HTTP payload instead of the URI.

    Secondly, you should either include a hidden iframe for javascript to access the page for which generate the PDF. On successful execution of the AJAX call (or whatever method you use), you can then redirect the page to your desired destination.

    评论

报告相同问题?

悬赏问题

  • ¥15 活动选择题。最多可以参加几个项目?
  • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型
  • ¥15 vs2019中数据导出问题
  • ¥20 云服务Linux系统TCP-MSS值修改?
  • ¥20 关于#单片机#的问题:项目:使用模拟iic与ov2640通讯环境:F407问题:读取的ID号总是0xff,自己调了调发现在读从机数据时,SDA线上并未有信号变化(语言-c语言)
  • ¥20 怎么在stm32门禁成品上增加查询记录功能
  • ¥15 Source insight编写代码后使用CCS5.2版本import之后,代码跳到注释行里面
  • ¥50 NT4.0系统 STOP:0X0000007B
  • ¥15 想问一下stata17中这段代码哪里有问题呀
  • ¥15 flink cdc无法实时同步mysql数据