PHP会话和Ajax [英] PHP session and Ajax
问题描述
我创建一个会话变量并存储在一个值123456。 我需要另一个网页,使用AJAX呼吁该值。使Ajax调用时,我无法访问会话变量。在session_start()是在两页的顶部。我甚至试着写的实际会话值从阿贾克斯函数调用的页面txt文件,但该文件竟然一片空白。
I've created a session variable and stored a value "123456" in it. I need that value on another page that is called using ajax. I cannot access the session variable when making the ajax call. session_start() is in top of both pages. I even tried to write the actual session value to a txt file from the page that the ajax function calls, but the file turned out blank.
怎么办?
推荐答案
您不能访问从Javascript PHP的会话信息(我假定这就是你想要做的事)。您可以将它作为一个隐藏字段或JS(用PHP动态添加)到第二页,将其添加到普通饼干,或从PHP提供它作为一个AJAX请求的响应,但我认为这些都是你唯一的选择。
You cannot access PHP session info from Javascript (I'm assuming that this is what you're trying to do). You can pass it in as a hidden field or in the JS (dynamically added with PHP) to the second page, add it to a regular cookie, or provide it from PHP as a response to an AJAX request, but I think those are your only options.
这篇关于PHP会话和Ajax的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!