JQuery UI Autocomplete - catch HTTP errors from source

I am using the jQuery UI Autocomplete plugin to create a quick search bar that populates a drop down list of matched items.

Everything works fine, but I would like to prepare my plugin for handling HTTP errors, as well as from ajax call.

I have not found a way to handle this. I read the documentation: http://jqueryui.com/demos/autocomplete/ , but it seems that such an event or callback is not called an “error” that can be used for this scenario.

I would like to receive a warning window informing the user about an error that occurred on the server side.

Anyone give me an example of this?

Thank!

+5
source share
1

http://jqueryui.com/demos/autocomplete/ , , . , HTTP- jQuery ajax- :

    $( "#autocomplete" ).autocomplete({
        minLength: 2,
        source: function( request, response ) {
            $.ajax({
                url: "query.php",
                data: { query: request.term},
                success: function(data){
                    response(data);
                },
                error: function(jqXHR, textStatus, errorThrown){
                    alert("error handler!");                        
                },
              dataType: 'json'
            });
        }
    });​
+11

All Articles