I would recommend using a generic error alert function. This saves
having to add an error: function() to each ajax call you use.

Here is my function. It uses jQuery UI to improve the appearance of
the error announcement and allow for html formatting:

//javascript
$(document).ready(function() {
        $.create('div', {'id': 'ajax_error', 'title': 'Ajax Error'}).appendTo
('body');

        $('#ajax_error').dialog({
                autoOpen: false,
                resizable: true,
                modal: true,
                height: 250,
                width: 450,
                buttons: {
                        'Close': function() {
                                $(this).dialog('close');
                                $(this).html('');
                        }
                }
        });

        $('#ajax_error').parent().addClass('ajax_error');

        $("#ajax_error").ajaxError(function(event, request, settings){
                $(this).html("<strong>While requesting page:</strong><br />\n 
<em>"
+ settings.url + "</em><br />\n <br />\n <strong>Message:</strong><br /
>\n <em>" + request.statusText + "</em>");
                $(this).dialog('open');
        });

});
//end javascript

I include the line:
        $('#ajax_error').parent().addClass('ajax_error');
So that you can style the error dialog differently to your main dialog
style, for example:

//css
.ajax_error .ui-dialog-titlebar{
        background-color:#Fbb !important;
        background-image:none !important;
}
//end css

This is the first one I have built, so it may be possible to improve
the feedback, and doesn't respond to thrown errors, but could easily
be adapted,

Reply via email to