khanahk Posted August 11, 2012 Report Share Posted August 11, 2012 I'm not yet a JSON/AJAX master so I don't know how to do this. I need a $_SESSION['name'] PHP variable to work with in my jQuery stuff and I don't know how to access it... consider: // the 'who is typing' shindig $.ajax( { url: "whos_typing.html", cache: false, success: function(whos) { // here I need to access $_SESSION['name'] and do stuff with it $("#soandso").html(whos); //Insert who's typing into the #soandso div } }); Quote Link to comment Share on other sites More sharing options...
falkencreative Posted August 11, 2012 Report Share Posted August 11, 2012 You can do something like this, by mixing Javascript and PHP: var name = <?php echo $_SESSION['name']; ?>; Make sense? I think that is probably the easiest way. Another way might be to use use AJAX to retrieve the variable, but that seems like an unnecessary amount of work compared to simply echoing it out in the page. 1 Quote Link to comment Share on other sites More sharing options...
khanahk Posted August 12, 2012 Author Report Share Posted August 12, 2012 Thanks Ben, for the concept (simple enough!). I found that var myvar = <?php echo json_encode($_SESSION['name']); ?>; is 'safer' for the 'PHP to JS' transfer... Quote Link to comment Share on other sites More sharing options...
falkencreative Posted August 12, 2012 Report Share Posted August 12, 2012 Good point. Depends on what the session variable contains. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.