[autocomplete] stopping additional ajax requests when starting letters already searching

[autocomplete] stopping additional ajax requests when starting letters already searching

It would be great for an option to not start a new search when a search that could contain the data is currently going.

This is what currently happens:
Lets say I want to type "detroit" fast (ajax backend, query not currently cached or cache expired):
- search begins on "de" (minChars = 2)
- I keep typing fast before "de" search results come back
- "det" starts loading, "de" search is aborted (! but still is trying to load on the backend)
- "detr" starts loading, "det" search is aborted (! but still is trying to load on the backend)
- "detro" starts loading, "detr" search is aborted (! but still is trying to load on the backend)
- "detroi" starts loading, "detro" search is aborted (! but still is trying to load on the backend)








This continues and as it happens the server gets more loaded trying to fetch now 5 queries when really the first "de" query would've sent back all the data needed. The more aborted queries, the more server load and the slower the response.

Pretty much what I would like added is an option to do this:

  1. if (dontSearchNewTermIfContainsCurrentTerm && newTerm.substr(0, currentTerm.length) == currentTerm) {
      // don't do new ajax search, wait for current search to
      // return results and then autocomplete newTerm on those results
    }



in the code above, newTerm would be "detroi" and currentTerm would be "detro"

I've tried to add the feature myself but my javascript skills have failed me. If anyone could help that'd be great.

Thanks,
Adam