views:

295

answers:

1

I'm having a hard time working out a design pattern in Jquery to control multiple AJAX and Animations. I of course have the AJAX and Animations bound to some events like 'click' but I'm trying to keep the code modular with functions and adding wrapper methods ($.fn), but I don't know how to get code to run when a function or a wrapper method is complete.

EDIT: Ok, it's a bit challenging to add in some sample code. So here's some pseudo code:

clickEventFunction(){

ajaxRequest();
ajaxRequest2();
ajaxRequest3();
animationFunction();

}

after all ajaxRequests complete I want an animation to fire off.

+3  A: 

As others have said, you can use a callback after each AJAX request is completed. In the callback you can use a counter or such to keep track of which requests have completed - once they are all complete, just trigger your animation.

Justin Ethier
That's what I'm doing now...it seems like a good idea, but it doesn't seem very graceful.
GreenEggs