首页 > 解决方案 > 如何将 JQuery 值发送​​到 php SESSION

问题描述

我尝试将 JQuery 值发送​​到 SESSION,这是代码(MVC)

$(document).ready(function(){

    $("#tbody th").click(function(){
        var id = this.id;
        $("#"+id).focus();
        $("#send").val(id);
    });
});

在 HTML 中:(form.php)

<form action="edit.php" method="post">
<input type="submit" name="choix" value="retour">
<input type="hidden" id="send"  name="send" value="">
<input type="submit" name="choix" value="edit" formaction=".../edit/$_SESSION['id']">"
<input type="submit" name="choix" value="delete" formaction="......."

在控制器中:

public function editAction(){
    $_SESSION['id'] = $this->_request->post('send')? $this->_request->post('send') : '';
    (...)
}

当页面提交(发送)时,我有 SESSION['id'],但在 URL 中,我有“localhost/.../edit/”,这意味着 SESSION 值不会发送到 URL。如何同时发送值?感谢您的回答

标签: phpjqueryinput

解决方案


$_SESSION['id'] = $value

不是设置会话 ID 的正确方法,请使用

$value = $this->_request->post('send')? $this->_request->post('send') : '';
session_id($value);
session_start();

这应该使用您的新 ID 创建一个新会话,如https://www.php.net/manual/en/function.session-id.php中所述


推荐阅读