doudanma9706 2014-04-10 11:37 采纳率: 100%
浏览 25

php执行javascript功能

The following is the code I use in an Order Confirmation module. I am creating a pdf file using fpdf and also sending an email. Subsequently, I clear out a shopping cart and redisplay the menu.

In the code below, I have commented out the creation of the pdf file. When I do this the email is sent and the cart is emptied by the javascript code

            <script type="text/javascript">
                doCart(\'EmptyCart\',\'0\', \'0\', \' \', \'partCheckOut\'); 
            </script>

but if I uncomment the code for the creation of the pdf:

            $pdf->getHdrDtl();
            $pdf->Header();
            $pdf->Footer();
            $pdf->generatePDF();

the pdf file is created, the email is sent, but the cart is not emptied and the menu is not redisplayed.

Does anyone have any suggestions or ideas?

if (isset($_POST['confirm']))
{ 
        $Cart->ConfirmOrder();
            /*
            $pdf->getHdrDtl();
            $pdf->Header();
            $pdf->Footer();
            $pdf->generatePDF();
             * 
             */
        $Cart->sendOrderEmails($dealer_email);
            echo '
            <script type="text/javascript">
                doCart(\'EmptyCart\',\'0\', \'0\', \' \', \'partCheckOut\'); 
            </script>
            ';
        $group = $_SESSION['group'];

        if ($group == 1){
                header("Refresh: 1; ./admin_menu.php");
                    exit;
        }
        if ($group == 2){
                header("Refresh: 1; ./user_menu.php");
                    exit;
        }
        if ($group == 3){
                header("Refresh: 1; ./admin_menu.php");
                    exit;
        }
}
  • 写回答

1条回答 默认 最新

  • doudi7570 2014-04-10 15:47
    关注

    I don't know how your $pdf->generatePDF() is acting, but it looks like it generate the PDF inside the current page. The page is no more an HTML page but a PDF one. Consequently you can't write any javascript code into the page (or any html or text directly, you must use the FPDF functions to insert data into the PDF, and before the generation of the document).

    And you definitely can't send any PHP header after sending data to the browser. If you have to redirect after sending data, use javascript redirections.

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog