问问题ajax和PHP SESSION变量 [英] Ask question ajax and PHP SESSION variable
问题描述
你好我所有的PHP会话变量的问题;实际上问题是关于我在php文件中创建的会话变量,并且无法在ajax请求的另一个中访问。
以下是ajax.html的代码发送ajax请求的页面:
hello all i've a problem with php session variables; in fact the issue is about a session variable that i've created in a php file and can't be accessed in another one requested by ajax.
below is the code of ajax.html the page from witch an ajax request is sent :
console.log('JQuery Ready')
$.get(
'http://localhost/php_files/ajax.php',
false,
function(data,status){
console.log('data is'+data+' '+'status is ' +status);
},
'text'
);
Ne xt页面请求ajax.php
Next the Page Request ajax.php
if(isset($_SESSION['ses'])) echo 'session working';
else echo ' session not working';
最后文件我在哪里创建了会话变量:
And Finally the file Where i 've created the session variable :
session_start();
$_SESSION['ses']='session';
echo $_SESSION['ses'];
我该怎么做才能解决这个问题?
我尝试了什么:
我试图用ajax将数据发送到php页面
what should i do to fix this problem ?
What I have tried:
i've tried to send data with ajax to a php page
推荐答案
.get(
' http:/ /localhost/php_files/ajax.php',
false,
函数(数据,状态){
console.log (' 数据为' + data + ' ' + ' 状态为' + status );
},
' text'
);
.get( 'http://localhost/php_files/ajax.php', false, function(data,status){ console.log('data is'+data+' '+'status is ' +status); }, 'text' );
N.对页面请求ajax.php
Next the Page Request ajax.php
if(isset(
_SESSION [ ' ses'])) echo ' 会话工作';
else echo ' < span class =code-string> session not working';
_SESSION['ses'])) echo 'session working'; else echo ' session not working';
最后文件我在哪里创建了会话变量:
And Finally the file Where i 've created the session variable :
session_start();
_SESSION [' ses'] = ' session';
echo
_SESSION['ses']='session'; echo
这篇关于问问题ajax和PHP SESSION变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!