在php中将会话从jquery设置为会话

在php中将会话从jquery设置为会话,php,jquery,Php,Jquery,我有一个php页面来执行查询。当我需要来自另一个使用jquery的会话页面的参数时。那么,如何从jquery中的会话设置php中的会话。请检查我的代码并给我解决方案。谢谢 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script> <script src="https://code.ciphertrick.com/demo/jquerysessio

我有一个php页面来执行查询。当我需要来自另一个使用jquery的会话页面的参数时。那么,如何从jquery中的会话设置php中的会话。请检查我的代码并给我解决方案。谢谢

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://code.ciphertrick.com/demo/jquerysession/js/jquerysession.js?d56ac9"></script>
<script>
$(document).ready(function(){ 
var sDecode = $.session.get("sesDecode"); 
alert(sDecode);      
}); 
</script> 
<?php
include('connection.php');  
$content= ==> how to get " sDecode " ???
$upd = mysql_query("UPDATE t_modules set content='$content' where id_t_modules='3'") or die(mysql_error());  
?>

$(文档).ready(函数(){
var sDecode=$.session.get(“sesDecode”);
警报(SDE代码);
}); 

您可以让PHP从会话变量中填充Javascript变量

<?php session_start(); ?>
<html>
...
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script>
$(document).ready(function() {
    var sDecode = <?php echo json_encode($_SESSION['sDecode']); ?>;
    alert(sDecode);
</script>

...
$(文档).ready(函数(){
变量sDecode=;
警报(SDE代码);

您可以使用ajax将参数发送到php文件,如下所示

$.ajax({
        url: "connection.php", 
        data: "Session="+$.session.get("sesDecode"), 
        type: "POST", 
        dataType: 'json',
        success: function (e) {
            console.log(JSON.stringify(e));
        },
        error:function(e){
            console.log(JSON.stringify(e));
        }
    });

PHP在Jquery之前执行,因此在从会话获取参数后使用ajax进行查询

注意,这两种解决方案都需要您检查输入,因为用户可能会修改输入

使用Ajax 获取
sDecode
的最佳方法可能是通过(AJAX)将其发送到一个PHP页面,该页面将注册会话值(在对其进行适当检查之后)

您可以通过以下方式在PHP中获得:

$sDecode = $_POST["d"]; // Please test the input here!
您可能需要使用
.serialize()
,然后根据内容和处理方式在PHP中取消序列化

使用重定向 您只需重定向到页面并将其作为GET值直接传输:

window.location.href=”session.php?d="+sDecode;
然后在session.php页面上,您将使用以下代码阅读它:

$sDecode = $_GET["d"]; // Please test the input here!

您需要使用AJAX来获取PHP会话变量。jQuery会话与PHP会话无关。我可以使用的实际数据是TinyMCE textarea的内容。如果发送的值太长,是否可以通过AJAX传递参数?因此,我保存会话可能是您可以查看此链接:,这是真实的我的情况..请…这不是答案对于这个问题,最好是发表评论。别担心@Samir Nabil,我们都在尝试(这只是给下一次的建议):-)我认为他实际上是在问相反的问题(从jQuery到PHP),但是你的回答也很有意义,因为这个问题并不清楚。
$sDecode = $_GET["d"]; // Please test the input here!