PHP session not working with JQuery Ajax?

前端 未结 2 1440
名媛妹妹
名媛妹妹 2020-12-21 02:40

Update, Solved: After all this I found out that I was calling an old version of my code in the update ajax. \'boardControl.php\' instead of \'boardUpdate.ph

相关标签:
2条回答
  • 2020-12-21 03:05

    From the small snippet of code we have, it's difficult to tell what your problem might be. What I can say is that session_start should be one of the first things you do on each page where you're expecting to use the session. After that, I would just immediately do a var_dump of $_SESSION to see that the data is in there (put a die right after that). It is quite possible that your true problem lies somewhere else, and that the session is in fact working. Is there a problem with your login code, for example, that is causing it to wipe out the session?

    You can use Firebug to look at the raw results of your AJAX calls, which should be helpful, since your script appears to work if you directly visit the page.

    Cases where I've seen sessions not work as expected have generally been that session_start is being called too often or too late. The other possibility is that you have an insanely short timeout, but that sounds unlikely.

    Finally, you can make sure that your PHP install is set to use cookie sessions. It's very unlikely at this point that it wouldn't be, but you could look.

    0 讨论(0)
  • 2020-12-21 03:09

    One potential problem in this code is the use of $.get - it is cached by IE, so your server code doesn't run every time. Try using $.ajax with cache set to false:

    $.ajax({
      type: 'GET',
      url: 'includes/boardControl.php',
      cache: false,
      data: {play: value, bid: bid}
    });
    
    0 讨论(0)
提交回复
热议问题