Question: I've build a livesearch with the jQuery.ajax() method. On every keyup events it receives new result data from the server.

The problem is, when I'm typing very fast, e.g. "foobar" and the GET request of "fooba" requires more time than the "foobar" request, the results of "fooba" are shown.

To handle this with the timeout parameter is impossible, I think.

Has anyone an idea how to solve this?

Answer: 
You can store and [`.abort()`](http://www.w3schools.com/dom/dom_http.asp) the last request when starting a new one, like this:

```
var curSearch;
$("#myInput").keyup(function() {
  if(curSearch) curSearch.abort(); //cancel previous search
  curSearch = $.ajax({ ...ajax options... }); //start a new one, save a reference
});

```

The [`$.ajax()`](http://api.jquery.com/jQuery.ajax/) method returns the [XmlHttpRequest](http://www.w3schools.com/dom/dom_http.asp) object, so just hang onto it, and when you start the next search, abort the previous one.
You should only start the search when the user hasn't typed anything for a while (500ms or so). This would prevent the problem you're having.

An excellent jQuery plugin which does just that is **delayedObserver**:

<http://code.google.com/p/jquery-utils/wiki/DelayedObserver>