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
2010-07-29 09:37:03
thats a global handler... how do I handle the autocomplete's call specifically?
Eran Kampf
2010-07-29 10:32:05
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
2010-07-29 10:53:52
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
2010-07-31 03:36:35
in function(request, response) what is request and response? can't fund anything in the docs about this...
Eran Kampf
2010-07-31 03:41:57
`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
2010-07-31 17:34:22