I am using jQuery to make some ajax calls and wonder how people handle this situation.
- An ajax request is made to the server to retrieve some info.
- Before the request returns another request is made. The first request is now invalid and out of date.
How do I tell that the initial request is now invalid and can be ignored when it returns. I only want to display the results of the second request and ignore (or cancel) the first.
jQuery returns the
XmlHttpRequestobject from the call toajax(), which I’ve used to achieve what you desire as follows:The net effect is that earlier requests’ responses are ignored if a subsequent request is made.