Kill duplicate jQuery AJAX queries

Is it possible to kill the previous ajax request?

We have tabular data very adjacent to each other. In the mouseover event of each of the data, we make a request to our server using the jQuery Ajax object and show a popup.

But, as we often move the mouse to other table contents, previous Ajax responses are displayed in pop-ups before the exact answer that is intended for that table content is displayed.

I need when a new Ajax request is generated, the previous request / response must be killed, so that the always expected last response is available inside the popup.

I use jQuery, PHP and Mysql to query the server.

+4
source share
4 answers

Failed to create a custom Javascript Sync object to be used by the function that creates subsequent ajax calls? Assign a sequentially generated identifier as a parameter for an incoming request call. Include the same identifier in the response. For each request, assign a new identifier increasing by 1 or any other logic. If the current identifier in the response does not match the current identifier in the shared object; ignore the answer, otherwise give an answer.

this would purely decide the state of the race. I'm not sure if there is a way to kill the request prematurely, but at least it won’t create an image problem that you are facing right now.

+5
source

Another option is to not initiate another request until the first is completed.

0
source

Yes and no. This is the point of Ajax. Be able to do something asynchronously. What you want to do is abort the request, which destroys the idea asynchronously. It is possible that you can do it if you send another request, set a value somewhere that indicates the number of requests, and then in the callbacks to your requests, check if the number of requests exceeds 1, if you ignore the answer.

0
source

Check out this AJAX Manager plugin . XmlHttpRequest has an abort () function, but jQuery does not have a wrapper for it.

0
source

All Articles