Goro
Goro

Reputation: 10249

How can I track AJAX calls and determine whether calling the callback function is no longer necessary?

I have a web application that is growing more complex. It makes heavy use of JavaScript based HTML generation and AJAX calls, and herein lies my problem:

Since I can't know how long an ajax call might take getting back to client side, I don't know when the callback gets actually executed. The user might have at that point navigated away from the element that originally caused the AJAX event, in which case this callback can cause some havoc. Is there a way to "expire" old callbacks ?

Are there any libraries that would offer that functionality? (I am using jQuery now but am not 100% familiar with it).

Thanks,

Upvotes: 0

Views: 122

Answers (2)

Amin Eshaq
Amin Eshaq

Reputation: 4024

You might want to look into Ajax Queue Manager. There are params you can set to abort old requests before sending a new one. I think that might be what your looking for.

Upvotes: 2

Jake Feasel
Jake Feasel

Reputation: 16955

Well, the simple answer is to check for the proper state of your app within your callback functions, before they do whatever it is they are doing that causes problems. For example, you could make sure that certain elements are still being hovered over.

Upvotes: 1

Related Questions