fabiomcosta / mootools-meio-autocomplete

A complete mootools Autocomplete plugin
http://www.meiocodigo.com/projects/meio-autocomplete/
32 stars 14 forks source link

Ajax request timing issue, with solution #7

Closed karptonite closed 12 years ago

karptonite commented 13 years ago

Say you are typing foobar in the search window, and the autocompleter sends an ajax request on "foo". If you continue to type "bar", the code may reach this.request.send in the request class before the first request has returned. In that case, it does not send another request, and instead will show the results of the "foo" query filtered on "foobar".

To fix this bug, I added the following lines to the "prepare" method of the Meio.Autocomplete.Data.Request class:

 if ( this.request.isRunning() ) {
  this.request.cancel();
 }

Just before this:

this.request.send({url: this.cachedKey});

This way, it will terminate any request in progress, and send a request on the most recent search term.

GCheung55 commented 12 years ago

After speaking with @fabiomcosta, it's unncessary. Passing in the link:'cancel' option for the request would work better.

fabiomcosta commented 12 years ago

thank you @GCheung55 :)

oscherler commented 12 years ago

You know what would be even better? To actually implement said fix that is so easy.