首先加载此页面test1.php
,然后点击CREATE VAR
(var $_SESSION["test_var"]
将创建),然后点击ALERT VAR
,我想知道如何才能获得警报变量结果再次加载页面
test1.php
<?PHP
session_start();
include("connect.php");
$sessionid = session_id();
?>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<div onclick="alert_fn()">ALERT VAR</div>
<br><br><br><br>
<script>
function alert_fn(){
alert("<?PHP echo $_SESSION["test_var"]; ?>");
}
</script>
<div onclick="create_var_fn()">CREATE VAR</div>
<br><br><br><br>
<div id="xx_span"></div>
<form id="fid" method="post" action="" ENCTYPE = "multipart/form-data">
<input type="hidden" name="xx" id="xx">
</form>
<script>
function create_var_fn(){
$.ajax
(
{
url: 'test2.php',
type: 'POST',
data: $('#fid').serialize(),
cache: false,
success: function (data) {
$('#xx_span').show();
$('#xx_span').html(data);
}
}
)
}
</script>
test2.php
<?PHP
session_start();
$_SESSION["test_var"] = "test";
echo $_SESSION["test_var"];
?>