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 在获取boss直聘的聊天的时候只能获取到前40条聊天数据
  • ¥20 关于URL获取的参数,无法执行二选一查询
  • ¥15 液位控制,当液位超过高限时常开触点59闭合,直到液位低于低限时,断开
  • ¥15 marlin编译错误,如何解决?
  • ¥15 有偿四位数,节约算法和扫描算法
  • ¥15 VUE项目怎么运行,系统打不开
  • ¥50 pointpillars等目标检测算法怎么融合注意力机制
  • ¥20 Vs code Mac系统 PHP Debug调试环境配置
  • ¥60 大一项目课,微信小程序
  • ¥15 求视频摘要youtube和ovp数据集