Often I have a situation where an action on the page causes an ajax request. When several of these actions have stacked up, each ajax request in turn comes in and does its action (maybe updating a list of items). This looks horrible. I’m trying to think of a way to have a request only update the list of items if no requests for the same type of thing are currently “pending”. Ideas?
Share
Your options:
Keep a list of request and check if the element is in the list. If it is in the list it means the request is happening. If it is not, you can start a request and add it to a list. Example on jsFiddle.
Before making a new request abort the existing one. This will cause the last request to go and others will be discarded, opposite from solution 1. Example on jsFiddle.