【发布时间】:2013-12-05 23:34:16
【问题描述】:
我有一个带有 $_SESSION 变量的 main.php 页面,我调用 ajax 来修改这个 var,在 ajax 上 $_SESSION var 发生了变化,但是当我在 main.php 上检查它时它没有。
我每个人都有session_start();,session_id(); 上的 ID 是相同的。
如果重新加载页面,值会被修改
main.php
<?php session_start();echo session_id();$_SESSION['equipo_g']=0 ?>
...
<!--SCRIPT CALLED BY BUTTON-->
<script>
function pdf(){
if (window.XMLHttpRequest){
xmlhttp=new XMLHttpRequest();
}
else{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function(){
if (xmlhttp.readyState==4 && xmlhttp.status==200){
document.getElementById("pdf").innerHTML=xmlhttp.responseText;
}
}
var e = document.getElementById("equipos_g");
var equipo = e.options[e.selectedIndex].value;
xmlhttp.open("GET","test.php?r="+equipo,true);
xmlhttp.send();
}
</script>
...
<!--Trigger a func to call the ajax-->
<button type="button" onclick="pdf();">Preparar Grafica</button>
...
<div id"pdf"></div>
...
test.php
<?php
session_start();
$r=$_GET["r"];
$_SESSION['equipo_g']=$r;
echo $_SESSION['estacion_g'];//The change is done
//Run a script that use $_SESSION['equipo_g']
echo '<button type="button" onClick="mostrar_graf1();" id="bot_grafica">Graficar</button>';
exit();
?>
【问题讨论】:
-
请出示一些代码。
-
检查一下。我会在这里通宵XD
标签: php ajax session session-variables