Using Session Variables inside an ajax document
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!
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.
I had changed my session var to memberName
精彩评论