2

I have writen searching in my site and now I am trying to make it search every time I start printing. So now I am sending many requests which contains different text to search for using AJAX one by one and every next reqest has to wait, before previous one is finished. Apperently I dont need old requests to be answered, but I need the only one response for the last request. How can I kill the queue of not actual requests in Django?

Does anybody know the answer?

mew666
  • 39
  • 1
  • 9

2 Answers2

1

On the server side, it's probably too late to cancel requests, but you can ignore the responses on the client side. I would suggest aborting a pending AJAX request before sending a new one.

Here is how: Abort Ajax requests using jQuery

Community
  • 1
  • 1
mif
  • 1,121
  • 8
  • 5
  • If the request was already sent this is useless since the lock is on the server-side. That's what should be aborted. – tiagoboldt Apr 05 '11 at 17:45
1

An easier way to do this could be by waiting a bit before sending your request to the server. After each input, set up a timer that stops the previous (setTimout) and only send the request if the timeout is met.

If a request was already performed and has not returned you can still kill it as suggested in another answer.

I'm not aware of how to stop other requests using django -- hope that it's not even possible, it would be a security thread if requests could be killed by others.

tiagoboldt
  • 2,426
  • 1
  • 24
  • 30