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: 
Assign a unique, incrementing ID to each request, and only show them in incrementing order. Something like this:

```
var counter = 0, lastCounter = 0;
function doAjax() {
  ++counter;
  jQuery.ajax(url, function (result) {
    if (counter < lastCounter)
      return;
    lastCounter = counter;
    processResult(result);
  });
}

```
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>