CakePHP:进行 AJAX 调用时无法访问会话

发布于 2025-01-13 14:20:13 字数 338 浏览 3 评论 0原文

这个问题适用于 CakePHP 4.3:

在我的操作中,我正在访问会话。对于正常的 GET 请求,一切正常。如果我通过 AJAX 请求调用相同的操作,我将无权访问会话。这是为什么?

例如,即使这样也不起作用:

public function select3() {
  debug($this->request->getSession()->read());
}

对于 GET 请求,会打印会话。对于 AJAX 调用,会打印一个空数组。

AppController 是否未针对 AJAX 请求进行调用?

任何帮助表示赞赏!

This question is for CakePHP 4.3:

In my action, I am accessing the session. For a normal GET request, everything works fine. If I call the same action through an AJAX request, I do not have access to the session. Why is that?

For example, even this does not work:

public function select3() {
  debug($this->request->getSession()->read());
}

For a GET request, the session is printed. For an AJAX call, an empty array is printed.

Is the AppController NOT called for an AJAX request?

Any help is appreciated!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

攒眉千度 2025-01-20 14:20:13

首先,感谢“ndm”提供的帮助。

我在看到 URL 与某些内容混淆后解决了这个问题。
URL 中包含“server-4.2”,“server”是指向它的链接。
“server-4.2”和“server”似乎都混淆了身份验证控制器。
很高兴现在可以用了。

First, thanks to "ndm" for your offered help.

I solved it after seeing that something was mixed up with the URLS.
The URL has "server-4.2" in it, and "server" is a link to it.
Both "server-4.2" and "server" seemed to have confused the Authentication controller.
Glad it works now.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文