views:

22

answers:

2

Hi,

For some reason I've having problems reading this session variable within an ajax document, I've got this inside online.php:

` session_start();

if (isset($_SESSION['username'])) { $username = $_SESSION['username']; } `

For some Reason this is not setting username even when the session var is being used on the host page, i call on the php file every second using this

` $(document).ready(function() {

var refreshId = setInterval(function() { $('#timeval').load('online.php'); }, 1000);

$("#stop").click(function() { clearInterval(refreshId); }); }); `

Am I doing something wrong, or is this not even possible?? Any advice would really help thanks alot!

+1  A: 

you have to send response for ajax request as json array. after that - you can use it.

here is the sample googled tutorial: http://viralpatel.net/blogs/2009/04/jquery-ajax-tutorial-example-ajax-jquery-development.html

ps: i wonder that you didn't ever look what was returned back from server for your ajax request.

zerkms
hmm very interesting zerkms, well the problem was that i had forgotten that I had changed my session var to memberName instead of username thats why it didn't work...So it's my fault, sorry to have wasted your time.It's working perfectly without json, so obviously thats not necessary, thank you
Pete Herbert Penito
A: 

I had changed my session var to memberName

Pete Herbert Penito