tags:

views:

40

answers:

1

I'm using the jQuery Autocomplete control to autocomplete from the server via an AJAX call. I implemented the search event to show a "Loading..." animation while results are being fetched from the server. I want to disable that animation and show a message if fetching the autocomplete results from the server failed (timeout or whatever) Whats the best way to do that?

A: 

Have a looksie at the jQuery.ajaxError method, which allows you to setup a default error callback for all ajax calls; http://api.jquery.com/ajaxError/

peol
thats a global handler... how do I handle the autocomplete's call specifically?
Eran Kampf
I guess you're using source: "url" --- You could use a callback function in source instead, and do a manual ajax inside it, that'll allow you to also specify a error callback. E.g. `source: function(request, response) { $.ajax({ url: 'url', data: request, /* Success and error callbacks */}` -- You then use `response(myAutocompleteArrayHere)` in the success/error callbacks.
peol
umm, I dont think I got the last comment. If the jQuery autocomplete source option is a function that calls $.ajax wont that function return before the ajax's success callback gets executed?
Eran Kampf
in function(request, response) what is request and response? can't fund anything in the docs about this...
Eran Kampf
`request` is the object containing the request information, e.g. `request.term` for the current term they're searching for, `response` is the callback function you should use to return the array with options that matched, e.g. `response(['some', 'array', 'returned', 'by', 'web service']);` -- If you click "view source" on this page: http://jqueryui.com/demos/autocomplete/#remote-with-cache, you'll see what I'm talking about.
peol