[英]Using Ajax to post JSON to php session
I'm trying post some JSON to a PHP file that in turn creates a PHP session.我正在尝试将一些 JSON 发布到 PHP 文件,该文件进而创建 PHP Z21D6F40CFB5119082E52E524 I have 2 JSON blocks that I want to add to their corresponding PHP session.我有 2 个 JSON 块,我想将它们添加到相应的 PHP session 中。
Can someone help in identifying the problem?有人可以帮助确定问题吗? The sessions do not get populated with the JSON data.会话不会填充 JSON 数据。
oneoff_json and monthly_json do return JSON values. oneoff_json 和monthly_json 确实返回 JSON 值。
var oneoffOptions = JSON.stringify(oneoff_json);
var monthlyOptions = JSON.stringify(monthly_json);
$.ajax({
url: "<?php echo get_stylesheet_directory_uri(); ?>/includes/set_session.php",
type: 'post',
dataType: 'json',
data: { oneoffOptions: oneoffOptions, monthlyOptions: monthlyOptions },
});
$_SESSION['oneoffOptions'] = $_POST['oneoffOptions'];
$_SESSION['monthlyOptions'] = $_POST['monthlyOptions'];
I forgot to decode the json at the PHP create session.我忘记在 PHP 创建 session 时解码 json。 All works now.现在一切正常。
$_SESSION['oneoffOptions']=json_decode($_POST['oneoffOptions'])
$_SESSION['monthlyOptions']=json_decode($_POST['monthlyOptions'])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.