如何使服务器在异步设置时确认浏览器状态


How to make the server acknowledge a browsers state when set asynchronously

请耐心等待,我需要帮助。

在我的网站:

  1. index.php -以这种形式显示20个链接:

    $result = mysql_query("my query");
    while($slice = mysql_fetch_assoc($result)){
         $url = $slice['url'];
         $perf  = $slice['perf']; 
         <a class="ajaxquery" data-title="<? echo $perf; ?>" href="$<? echo $url ?>">anchor</a>
    endwhile;
    
  2. 如果有人点击20个链接中的一个,我有这个ajax代码,它看到哪个$perf被点击,将数据发送到session.php:

    function ajaxsession(){
        $("a.ajaxquery").click(function() {
            var perf = $(this).data('title');
            $.ajax({ type: "POST", url: "/session.php", data: "perf="+perf, success: function(html){ $("#results").append(html); } });
        });
    }
    
  3. 这段代码向session.php发送如下信息:

    session_start();
    $_SESSION['perf'] = $_POST['perf']; // Store session data
    
  4. 在我的single.php页我调用存储在会话中的变量:

    echo $_SESSION['perf'];
    

single.php我得到正确的$perf,只要我回到index.php 使用主页链接

如果我回到index.php使用浏览器后退箭头,然后$perf不使用onclick jQuery代码更新。

你知道为什么会发生这种情况吗?我在想,也许我应该以某种方式破坏会话,一旦它达到single.php。这是个好主意吗?

'后退按钮'通常会返回并加载页面的缓存副本。如果你想让"上一个"页面在用户"返回"时自动重新加载,你必须在第一次加载时发送无缓存标题的页面。