Well, one thing you could do is to put your other ajax call on an interval. You have a boolean that says whether or not authentication was successful. Each time the interval tries to run your second ajax call, it first checks to see if this boolean is true, if it is, make the call. If its not, do nothing. Once it has been run, disable your interval.
cheers Michael Lawson Development Lead, Global Solutions, ibm.com Phone: 1-276-206-8393 E-mail: mjlaw...@us.ibm.com 'When seen from outer space, our beautiful blue planet has no national boundaries.' http://www.givesmehope.com/ From: Bonji <benho...@googlemail.com> To: "jQuery (English)" <jquery-en@googlegroups.com> Date: 01/20/2010 12:43 PM Subject: [jQuery] Re: Call ajax on sucess response from a previous ajax Ok basically on click of any anchor tag this ajax script calls a php script called sessions.php //data var data = 'do=update'; //run ajax $.ajax({ //post rather than get (default) type: "POST", //pass to php script url: "/php-bin/sessions.php", //send data data: data, //data type dataType: 'json', //timeout timeout: 5000, //cache cache: true, //success function success: //result function function(result){ //if result.error if(result.error) { //redirect location.href=result.redirect; } }, //error function error: //error function function(){ //load facebox internal error faceboxURL ('php-bin/alert.php?do=internalError'); } });//ajax It posts 'do=update' as data to the php script which selects the correct php switch. The php script then checks if the user is logged in and updates the users timestamp. All session data is stored in a mysql database. The datatype returned is in a json array. So on success the ajax checks the array value 'result.error' and if set to true it currently redirects the user to the 'result.location' value which is defined in the json array. In other words... if the user was not found or their session has expired it redirects the user to the location set in the php script as they need to be authenticated to use the site. However this means that the anchor tag is only checking user data. What about its original function which is also an ajax call? I thought i might be able to add the second ajax call as an else statement to the if(result.error) statement. In other words... if the user is authenticated and the timestamp was updated run the origianl anchor tag function (which is also an ajax call) At the moment the two ajax calls run at the same time which is fine except the second ajax is used to load content to the page. The first ajax call completes half way through the second ajax call cycle. In other words... if the user was not found or their session has expired the second ajax still loads content to the page but gets cut off half way through loading while the first one is redirecting. This is ok but it is scrappy looking to see the page trying to load content into a div (second ajax) while the first is redirecting. I hope i havn't lost you. I've tried to explain as clearly as i can. Ben On Jan 20, 4:53 pm, Michael Lawson <mjlaw...@us.ibm.com> wrote: > Do you have any code to share? > > cheers > > Michael Lawson > Development Lead, Global Solutions, ibm.com > Phone: 1-276-206-8393 > E-mail: mjlaw...@us.ibm.com > > 'When seen from outer space, our beautiful blue planet has no national > boundaries.' > > http://www.givesmehope.com/ > > From: Bonji <benho...@googlemail.com> > > To: "jQuery (English)" <jquery-en@googlegroups.com> > > Date: 01/20/2010 11:46 AM > > Subject: [jQuery] Call ajax on sucess response from a previous ajax > > Hi. > > Im not sure if this is the correct way of going about this so i > thought i'd ask the experts... > > I have a jquery ajax script which simply returns true or false based > on the response from a php script. > > This works just fine. > > However i want to know if it is possible to load a second ajax call if > the first returns true? > > I've tried placing the second $.ajax inside the success fuction of the > first $.ajax but the second call never triggers or doesn't return > anything. > > Is there a way of queuing $.ajax functions so they fire on after > another? > > graycol.gif > < 1KViewDownload > > ecblank.gif > < 1KViewDownload
<<inline: graycol.gif>>
<<inline: ecblank.gif>>