dreljie602951 2010-10-07 07:07
浏览 70
已采纳

AJAX请求时不保留会话信息

i am creating session while rendering the page. After that i am calling the AJAX page every 4 seconds. the AJAX page doesnt gettign the Session information.

What may be the reason. Whether ajax requests dont maintain Session information?

Code:

Normal HTML

<body onload="timerint(11)">
<div style="display:none;">
    <button id="prev"><<</button>
    <button id="next">>></button>
</div>

<div class="anyClass">
    <ul id="news-ul">
        <?php 
          include('render_latest.php');
        ?>
    </ul>
</div>
</body>

render_latest.php

<?php
session_start(); 
$con = mysql_connect("localhost","root","root");
mysql_select_db("test_db", $con);
$i=1;

$lastresult=mysql_query("SELECT MAX(epoch) as latestepoch FROM list_data");

while($row = mysql_fetch_array($lastresult))
  {
    //$_session['lastepoch'] =  $row['latestepoch'] ;
    $_session['lastepoch']=12345;

  }

$result=mysql_query("SELECT * FROM list_data order by epoch desc LIMIT 4 ");
while($row = mysql_fetch_array($result))
  {
    echo '<li>';
    echo $row['list_item'] . '<br/>' ;
    echo $row['epoch'] . '<br/>';
    echo $_session['lastepoch'];
    echo '</li>';
  }

?> 

AJAX Page

<?php
session_start(); 
$t=$_SESSION['lastepoch'];
$con = mysql_connect("localhost","root","root");
mysql_select_db("test_db", $con);

$result=mysql_query("SELECT * FROM list_data order by epoch desc LIMIT 1 ");

while($row = mysql_fetch_array($result))
  {
    echo '<li>';
    echo $t;
    echo $row['list_item'] ;
    echo '</li>';
  }

?> 
  • 写回答

2条回答 默认 最新

  • duandian2725 2010-10-07 07:26
    关注

    The session data are stored usually in cookies for all browsers, or you can use the query string of your request to pass parameters. eg: .../render_latest.php?lastepoch=123456 and read the lastepoch parameter in your php.

    Or you can use HTML5 client-side storage in modern browsers.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)