0

我有一个链接,单击该链接时,会调用 jquery ajax 函数从 php 页面获取数据,并将返回的 html 放入弹出 div 中。

返回的 html 实际上是一个表单。在 php 中,我正在查询数据库以获取与用户规格匹配的许可证列表,并将它们保存在一个数组中。然后,我将数组保存在 $_SESSION 变量中。

当用户提交此表单时,它会调用另一个 ajax 函数来获取更多 html 用于弹出 div(向导样式)。我需要在这里使用存储在 $_SESSION 变量中的数组,但我得到的只是一个空白数组(缺少值)。

这是php代码的示例

//step 1
$renewable_licenses = db_query_array($sql);
$_SESSION['renewable_licenses'] = $renewable_licenses;
$_SESSION['hello'] = "hello!";
print_r($_SESSION); //I can see all the session vars, 
                      //including the array with all it's values, and "hello!"

//step 2
print_r($_SESSION); //I see the standard session vars set in other pages, I see
                 //"hello!", I see [renewable_licenses] but it is an empty array!

ajax 工作正常,我看到表单和正确的字段都显示得很完美。我检查了两个 ajax 调用的 session_id,它们是相同的。session_start() 在两个页面上都被首先调用。为什么我不能在第二步中访问我的数组?

4

0 回答 0