AJAX请求处理失败$ _SESSION变量 [英] AJAX request fails to process $_SESSION variable
本文介绍了AJAX请求处理失败$ _SESSION变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个处理一个AJAX请求的JavaScript文件。这个请求处理一个PHP文件(正常工作)。但是,当我想在这个PHP文件叫我 $ _ SESSION
变量(或在我的课上的其他PHP文件实现的任何静态变量),它不承认(我回声
吧,我有一个 500错误
)。
I have a JavaScript file that processes an AJAX request. This request processes a PHP file (which works fine). But when I want to call in this very PHP file my $_SESSION
variable (or any static variable that are implemented in my classes on other PHP files), it isn't recognized (I echo
it, and I have a 500 error
).
在JS文件,我有:
$.ajax({
type: "POST",
url: "../classes/ajax/myfile.php",
data: "comment="+encodeURIComponent(text),
success: function(msg){
/* PHP returns the automatically assigned ID of the new comment */
}
});
和我的PHP文件,我测试我的变量,像这样:
and in my PHP file, I test my variable like so:
require_once '../Account.php';
$temp=Account::getCurrentAccount()->getId();
echo($temp);
exit;
是否有人有一个想法?
推荐答案
添加到您的AJAX PHP文件
Add this to your ajax .php file
if( !isset( $_SESSION ) ){ session_start(); }
在理想情况下,你会在一些常见的配置文件...
Ideally, you would have that in some common config file...
这篇关于AJAX请求处理失败$ _SESSION变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文