phnah
phnah

Reputation: 1781

Ajax Live Search multiple response at a time

According to this question, we use deboucing to make a live search like facebook

Facebook Style AJAX Search

But here is my case, when I set the timeout as 300ms, first I type query A and wait for 300ms then an ajax request is triggered, but when waiting for server to response for query A, I do another query B, and after 300ms, the response for query A finally shows up, and then immediately response for query B shows up too, so you see 2 results flashing, how to prevent this? (cancel the first request or something?)

Upvotes: 0

Views: 427

Answers (1)

Thomas
Thomas

Reputation: 8849

Depending on how many results you return I see 2 possible actions:

  • Don't make a new request but wait for the old one to complete and filter it with the new search value
  • Cancel the first request and start another one.

The first method will only work well when the first request returns more items than are displayed.

Upvotes: 1

Related Questions