php会话显示以前的会话值

时间:2013-06-11 05:26:21

标签: php javascript session session-variables

我从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并分配新会话之后才会出现。我怎样才能做到这一点?

1 个答案:

答案 0 :(得分:0)

修复jquery行

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

到此:

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

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