Sunday, 15 September 2013

JavaScript - Wait unitl ajax and its callback function finish

JavaScript - Wait unitl ajax and its callback function finish

I am building a web app that allows users to perform a number of actions
simultaneously. For example, user can open a list, delete a list, or add a
new list.
Each action makes an ajax call and executes a callback function to update
UI upon success. I want to make sure these actions are performed in a
serialized manner, so that the UI does not go out of sync. For example, if
user opens a list, but deletes a list a fraction of a second later,
depending on which ajax call finsihes first, it may display the list which
is supposed to be now deleted.
To accomplish this, for each action, I want to wait until an ajax call and
its callback function are finished. How can I achieve this?

No comments:

Post a Comment