在使用和时$_GET,我需要一些帮助。我已经构建了一个最小的工作示例来说明这个问题:$_SESSIONXMLHttpRequest
索引.php
<?php
session_start();
$_SESSION['current'] = 2;
?>
<html>
<head>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="ajax.js"></script>
</head>
<body>
<div id="content"><?php include('table.php'); ?></div>
</body>
</html>
表.php
<?php
if(isset($_GET['current']))
{
$_SESSION['current'] = $_GET['current'];
}
$current = $_SESSION['current'];
echo '<h1>Table Value = '.$current.'<br>';
?>
浏览.php
<?php
if(isset($_GET['current']))
{
$_SESSION['current'] = $_GET['current'];
}
$current = $_SESSION['current'];
echo '<h1>Browse value = '.$current.'<br>';
print "<input type=\"button\" value=\"Click here\" onclick=\"myfunc($current)\"/> ";
?>
ajax.js
function myfunc(input) {
xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET","table.php?current=" + (input+1),false);
xmlhttp.send();
document.getElementById("content").innerHTML=xmlhttp.responseText;
xmlhttp.open("GET","browse.php",false);
xmlhttp.send();
document.getElementById("target").innerHTML=xmlhttp.responseText;
}
我使用 Firebug 控制台来跟踪正在发生的事情。首先让我指出,我将 async 参数设置为 false,因为我的服务器请求非常小。当我单击该按钮时myfunc(2),它会执行并./table.php?current=3从./browser.php服务器请求。
我的想法是,由于我./table.php?current=3首先请求,会话变量$_SESSION['current']将设置为 3。但是当请求 browse.php 时,会话变量未设置!这是我单击一次按钮后发生的情况:

知道可能出了什么问题吗?提前致谢 :)