php - AJAX php 文件中的会话未更新
问题描述
我在更新名为“subs”的 SESSION 的值时遇到问题。当我单击 .userLink 时,应显示特定用户的个人资料。这行得通-所有个人资料信息都根据我单击的链接而变化。甚至我的会话也得到了正确的值。但只有一次。当我单击另一个用户链接时,个人资料信息会更改(名字、姓氏……),但我的会话值保持不变,直到我删除 cookie。然后我能够再次获得正确的价值。
我非常沮丧。我找不到错误。AJAX 工作正常,所有文件顶部都有 session_start()。
有人可以帮我吗?
JAVASCRIPT(AJAX 调用)
$(".userLink").click(function() {
var user = $(this).html();
var dataString = 'uzivatel='+ user;
$.ajax({
type: "POST",
url: "includes/showProfile.php",
data: dataString,
dataType: 'json',
cache: false,
success: function(result){
$("#otherProfile").toggle();
$("#nameSection h2").html(result[1]);
$("#nameSection h1").html(result[2]);
$("#Pbirthdate").html(result[3]);
$("#Pgender").html(result[4]);
$("#description").html(result[5]);
}
});
});
显示配置文件.php
<?php
session_start();
include 'connect.php';
$profileOwner = $_POST['uzivatel'];
$sql = "SELECT * FROM users WHERE username = '$profileOwner'";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
$_SESSION["subs"] = $row["userID"];
$firstname = $row["firstname"];
$lastname = $row["surname"];
$birth = $row["birthdate"];
$birth = date( "j.n.Y", strtotime($birth));
if($row["gender"] == "male"){
$gender = "MUŽ";
} else{
$gender = "ŽENA";
}
}
}
$file="../profiles/".$ID."/description.txt";
$imageFile="profiles/".$ID."/profileImage.jpg";
if(file_exists($file)){
$description = file_get_contents($file);
}
$array = array($ID,$firstname,$lastname,$birth,$gender,$description);
echo json_encode($array);
$conn->close();
?>
解决方案
推荐阅读
- botframework - Bot Composer 和 BotBuilder FacebookAdapter 导致“对象引用未设置为对象的实例”
- python - 将 pytorch 转换为 coreml 以实现逐元素最大操作
- python - 为什么 Python 在 Windows 上使用 cmd 会忽略 %PYTHONPATH%?
- javascript - 将此 Excel 公式转换为 Javascript
- apache-spark - 如何为特定行的数据集中的现有列添加值
- flutter - 使用 keycloak 进行 Flutter 应用程序身份验证
- python - Clean_field 函数无法与 updateview 一起正常工作。我们如何纠正这种行为?
- python - 使用 python 制作 TTS 应用程序,但适用于其他语言
- clickhouse - 覆盖 clickhouse-backup 默认配置
- php - 使用ajax提交表单后使用php重定向到主页