I use the following Ajax.Updater code to auto-complete (refresh) the
options within a select box according to text entered into an input

The code is part of a function which is envoke by the 'onkeyup' event
on the input:

new Ajax.Updater(targetSelect.identify(), xhrRequestUrl, {
        method: 'get',
        parameters: {
                match: inputControl.getValue()
        onCreate: targetSelect.disable.bind(targetSelect),
        onSuccess: (function(){

The problem: with large data sets, the ajax requests take long time to
process on the server, and then there's network lag, etc. This returns
in (sometimes) the responses come back in the wrong order. An example:

- user types 'abc', which sets off 3 requests, with 'match' param of
'a', 'ab', 'abc' respectively.
- due to server delay/network lag etc, sometimes the response for
'abc' comes back *before* the 'ab'  response
- select box ends up containing all entries match 'ab', rather than
only those matching 'abc'

The solution I've thought of:

Somehow make a callback function which short-circuits (i.e. aborts)
the Ajax.updater object if it's 'match' parameter is different from
the current value of 'inputControl' at the point where it's about to
empty and replenish the select box with the HTML from the response.

- Which callback will allow me to intercept Ajax.updater at this
point? Will this even work with Ajax.updater, or do I need to use
Ajax.request and update the contents of the select box element
manually if the condition for doing so are met?
- How can a callback access the 'parameters' which were set for the
request? Can it even? Will I need to duplicate 'match' into some local
variable - and even then how will the anonymous callback function get
at it?

Am I barking up the wrong tree altogether?


You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
For more options, visit this group at 

Reply via email to