GreenEggs
GreenEggs

Reputation: 527

Jquery AJAX / Animation Control Flow

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 ajax requests complete I want an animation to fire off.

Upvotes: 2

Views: 703

Answers (1)

Justin Ethier
Justin Ethier

Reputation: 134157

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.

Upvotes: 3

Related Questions