【发布时间】:2015-07-01 14:47:04
【问题描述】:
我想使用 jQuery 帖子更新 $_SESSION 数据。
最终我将found this script 作为“系统”的基础。
我创建了以下两个文件作为测试:
t1.php:
<?php
session_start();
/* After refresh, src should be visible */
echo print_r($_SESSION);
?>
<script src="//code.jquery.com/jquery-1.11.3.min.js"></script>
<img class="foo" src="img.jpg" />
<img class="foo" src="img2.jpg" />
<img class="foo" src="img3.jpg" />
<script>
$("img.foo").onclick(function()
{
// Get the src of the image
var src = $(this).attr("src");
// Send Ajax request to backend.php, with src set as "img" in the POST data
$.post("/t2.php", {"img": src});
});
</script>
t2.php:
<?php
session_start();
$_SESSION['imgsrc'] = $_POST['img'];
?>
很遗憾,刷新t1.php后没有生成src路径。$_SESSION['imgsrc']保持为空。
我已经尝试了一切,也许是为了得到一些东西?
希望你能帮忙!
【问题讨论】: