micah1701 Posted December 23, 2009 Share Posted December 23, 2009 I have a function in Javascript that uses jQuery's .get() function to tell my PHP script to update a $_SESSION value. it looks something like this: function updateSession(key,value){ $.get('updateSessionArray.php',{key:key,value:value}); } (the PHP code is inconsequential and works fine but I'll post it here so you get what I'm doing, it looks something like: <?php $_SESSION[$_GET['key']] = $_GET['value']; ?> This all works fine. When I call something like updateSession("username","Joe"); in JavaScript the $_SESSION array is updated and everyone's happy. Here's where my problem starts When I try to call the function multiple times at once it doesn't work. for example, I have a function that needs to update the $_SESSION several times, sort of like this: function createUser(){ updateSession("username","joe"); updateSession("favorite_color","blue"); updateSession("foo","bar"); } But when i try this, the original function only runs once - sometimes twice. So in the above example, the username would be set to joe and the favorite_color would be set to blue but foo would not be set to bar. Or perhaps it would but color wouldn't be set to blue. Or Only the username gets set. It would seem that once the function is busy running (and possibly waiting for a reply) it won't run again. Is that the correct behavior? and if so, is it a javaScript specific behavior or a jQuery thing. It seems odd though as, I'm not asking for it to wait for a response. I just want it to trigger the function to run independently multiple times. I originally wrote this script without jQuery and I never had a problem before. I admit though that I'm no expert so maybe I'm missing something? Am I just not wrapping my head around the way this should work? Any thoughts or comments would be appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/186164-jquery-cant-seem-to-figure-out-why-functions-arent-running-independently/ Share on other sites More sharing options...
micah1701 Posted December 23, 2009 Author Share Posted December 23, 2009 UPDATE: The PHP script that I'm linking to (in my example it was "updateSessionArray.php" has been running inside a CakePHP invornment. I moved it out of cake and, not only does it run faster for all ajax actions but it seems to be working fine now. When running in Cake it was taking a full 1 to 3 seconds to get my results back but now its near instant. So my original problem still stands (as I'd like to keep the PHP page in the cake framework) but I think this helps narrow down the problem to one of two things: Either 1) Its either CakePHP -- either putting some sort of limit on the number of requests or perhaps trying to cache results? or 2) its a jQuery/JavaScript issue having to do with the amount of time it takes to process the .get() function while waiting for a long response. Any thoughts in light of this revelation? Quote Link to comment https://forums.phpfreaks.com/topic/186164-jquery-cant-seem-to-figure-out-why-functions-arent-running-independently/#findComment-983157 Share on other sites More sharing options...
micah1701 Posted December 23, 2009 Author Share Posted December 23, 2009 In light of my last post, I added a php sleep() call to function to purposely slow it down by several seconds and it still worked fine - showing there's no correlation between jQuery/javaScript and the speed it takes PHP to process the .get() request (which I suspected). Thus, this must be a CakePHP issue. Topic Closed. Thanks for letting me think "out loud" by posting this here. Quote Link to comment https://forums.phpfreaks.com/topic/186164-jquery-cant-seem-to-figure-out-why-functions-arent-running-independently/#findComment-983163 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.