Weird ajax problem

I put together a search based on a text field and a form observer. The
observer triggers an ajax method that does a paginated search of a large
number of items and does a render :update to update the list of items
with the new contents based on the search. Pretty standard stuff.

The weirdness is that the very first character typed in the search term
field typically results in a large number of items to return. The
second character greatly reduces the size of the results, as do the
subsequent characters typed in.

What happens visually is that if you type a few characters quickly, you
get the expected short list of results…followed a second or two later
by the larger result set appropriate to the first character typed. The
logging confirms that the rails app is doing the right thing in the
right order.

It appears that it is simply the size of that first set of results that
is causing it to take longer to get to the browser, so it winds up being
displayed out of order.

Anybody run into something like this before? Did you come up with some
clever solution?

thanks,
Jeff

Jeff P. wrote:

I put together a search based on a text field and a form observer. …>
What happens visually is that if you type a few characters quickly, you
get the expected short list of results…followed a second or two later
by the larger result set appropriate to the first character typed. The
logging confirms that the rails app is doing the right thing in the
right order.

…>

thanks,
Jeff

Just a quick note in case somebody stumbles upon this doing a search
some day. The solution was actually to slow down the observer. I
changed the observer time to 1.5 seconds (used to have it at 0.1
seconds, when I didn’t understand the underlying mechanism that was
making it fail). Now when you type at either slow or fast speeds
everything gets to the browser in the proper order and all is well. It
basically just winds up not even seeing the first letter you type by
itself, but rather sees it together with the second letter when you are
typing at normal speeds. Typing really slowly, there is time for the
first response to get back to the browser before the second character is
typed into the search field.

Works well now.

jp