I have a shopping cart where a user can add more items, change quantity of existing items, remove items and such. For each of these actions, I do an async AJAX call to the server in order to update the Order total.
What happens is that if the user adds an item (action 1), I do the async call, and then the user changes the quantity of another item (action 2), I would like the response of action 2 to show up. Since these calls are async, maybe the latest response that I get is the one from action 1, and therefore the order total is incorrect.
What pattern should I follow to not trigger the same AJAX call until the previous one has finished?
To clarify:
The AJAX requests that are happening are the same ones. Say I do this $.get('destination_url'). I just need to make sure that that I don't do the same request until the previous one is done/failed.