0

我正在从 php 调用一个控制台应用程序,它给了我一些输出。执行控制台应用程序后,我必须在 div 中显示输出。我已将控制台应用程序的输出作为 SESSION 传递到另一个页面以显示它。我也在我的网页中使用了 ajax 和 javascript,这使它变得更加复杂。现在,当我打印输出时,div 中的输出是 SESSION 的先前值。我的代码如下:

主页面:

<!DOCTYPE html>
<html>
    <head>

                    $('#file').live('change', function()    
                    { 
                    $("#preview").html('');
                    $("#preview").html('<img src="images/loader.gif" alt="Uploading...."/>');
                    $("#imageform").ajaxForm(
                    {
                    target: '#preview'
                    }).submit();

                    <script type="text/javascript">
                    function myfunction()
                    {
                    $("#display").html('');
                    $("#display").html('<img src="images/loader.gif" alt="Uploading...."/>');
                    $("#retrieveimageform").ajaxForm(
                    {
                    target: '#display'
                    }).submit();

                     $('#tags').html('<?php include 'Tagsdisplay.php';?>');  
 %I want to include this only after it goes through the retrieveimage1.php page
 where the console application is called and the session is created but this is
 not happening the tags div is shown before the console application is called 
 and the other results are displayed on the display div
                     $('#tags').show();
                    };


                    </script>

        <title></title>
    </head>
    <body>
        <div id="maindiv">
                <div id="banner">
                <?php
                include 'Header.php';

                ?>
                 </div>
                <div id="wrapper">

                        <div id="imageupload">
                    <form action="uploadimage.php" method="post"
                         enctype="multipart/form-data" id="imageform">
                         <label for="file">Upload your image:</label>
                       <input type="file" name="file" id="file"><br>

                    </form>
                        </div>
                       <div id='preview'>  
                        </div>
                    <div id='tags'>

                    </div>

                       <div class="clear"></div>

                    <form action="retrieveimage1.php" method="post"
                           id="retrieveimageform">

                       ................................   

                         <input type="submit" name="search" value="Search" id="btnSearch" onclick="myfunction()">

                    </form>
     <div id="display"></div>

                 </div>

调用控制台应用程序并创建会话的retrieveimage.php:

          session_start();
          $start_time=  microtime(true);
        if (isset($_SESSION['img']))
        {   
                $image=$_SESSION['img'];
                $_SESSION['coarselbl1']=" ";
                $_SESSION['coarselbl2']=" ";
                $_SESSION['coarselbl3']=" ";
                $_SESSION['finelbl1']=" ";
                $_SESSION['finelbl2']=" ";
                $_SESSION['finelbl3']=" ";
                $_SESSION['finelbl4']=" ";
                $_SESSION['category']=" ";
                    if($_POST['cat']=='handbag')
                            {
                                 $_SESSION['category']="Bag";
                                 $cwt=$_POST["slider1"];
                                $fwt=$_POST["slider2"];
                                $twt=$_POST["slider3"];
                                $swt=$_POST["slider4"];

                                $addr="handbags31_fourth.exe $image $cwt $fwt $swt $twt";
                                  exec($addr,$data);

                                  $_SESSION['coarselbl1']=$data[2];
                                  $_SESSION['coarselbl2']=$data[3];
                                  $_SESSION['coarselbl3']=$data[4];
                   }

显示标签的TagsDisplay.php:

<?php
        session_start();
        echo $_SESSION['category']."<br/>";
   if($_SESSION['category']=="Bag")
    {
        echo "Coarse Color:   ".$_SESSION['coarselbl1'].",".$_SESSION['coarselbl2'].",".$_SESSION['coarselbl3']."<br/>";
        unset($_SESSION['coarselbl1']);
        unset($_SESSION['coarselbl2']);
        unset($_SESSION['coarselbl3']);


    }


?>

这里的问题是当我单击搜索按钮时调用 myfunction 并且标签 div 显示在显示 div 之前,并且打印的值是上一个会话值。我希望标签 div 仅在显示 div 显示并分配新会话后出现。我怎样才能做到这一点?

4

1 回答 1

0

修复 jquery 行

$('#tags').html('<?php include 'Tagsdisplay.php';?>'); 

对此:

$('#tags').html('<?php include "Tagsdisplay.php";?>'); 

(注意引号),因为您甚至不包括取消设置前一个会话值的文件。

于 2013-06-11T05:37:02.023 回答