dongzhi4073 2019-04-12 10:31
浏览 176

使用jquery ajax与php时的SESSION问题

I have my first script and when I click the forward button (.dev1) the next tab opens and a session is created with the value of former tab's selection.

If I want to change the selection; there is a back button (.ger1). It returns back to the first tab, and unset the session to have a new value (i checked it, there is no value).

After I change the selection and click the next button, the session has the first value again, not the new selection's value, although it hasn't any value after deleting. It requires refreshing the page on the first tab, then selecting the new selection.

//script to create session:

$(".dev1").click(function () {
    var action = "add";
    var kesim1 = $("#resimilk").data("kesim1");

    $.ajax({
        url: "action.php",
        method: "POST",
        data: {
            kesim1: kesim1,
            action: action
        },
    });
});

//script to delete session:

$(".ger1").click(function () {
    var action = "kesimsil";
    var kesim;

    $.ajax({
        url: "action.php",
        method: "POST",
        data: {
            kesim: kesim,
            action: action
        },
    });
});

action.php

if($_POST["action"] == "add"){

    $kesim1=$_POST["kesim1"];

    $_SESSION['kesim']=$kesim1;

    echo $kesim1;

}
if($_POST["action"] == "kesimsil") {

    $kesim=$_POST["kesim"];

    unset($_SESSION['kesim']);

    echo $kesim;

}
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
    • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
    • ¥15 matlab有关常微分方程的问题求解决,来真人,不要ai!
    • ¥15 perl MISA分析p3_in脚本出错
    • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
    • ¥15 ubuntu虚拟机打包apk错误
    • ¥199 rust编程架构设计的方案 有偿
    • ¥15 回答4f系统的像差计算
    • ¥15 java如何提取出pdf里的文字?
    • ¥100 求三轴之间相互配合画圆以及直线的算法