my question is: how can my php script send data like json and return to success or full function?
I tried to get this chat function to work on my site. Since it didn’t work, I created a rolled-up part of the code to check if this has anything to do with the json method.
I only tested if I could get the session name after phpscript was processed. What I get is "undefined" instead of "johndoe".
I have no idea what could be the problem. Obviously, the script works great for others if you see comments on the creators page.
this is my test code
<?php session_start(); $_SESSION['username'] = "johndoe" ; <script type="text/javascript" src="includes/jquery.js"></script> <script language="JavaScript"> $(document).ready(function(){ $("#testjson").click(function(e){ startJsonSession(); return false; }); function startJsonSession(){ $.ajax({ url: "jsontest.php?action=startjson", cache: false, dataType: "json", complete: function(data) { username = data.username; alert(username); } }); } }); </script> <?php { "username": "<?php echo $_SESSION['username'];?>", "items": [ <?php echo $items;?> ] } <?php exit(0); } ?>
thanks Richard
json jquery ajax php
Richard
source share