What are jQuery best practices regarding Ajax convenience methods and error handling?

Posted by JonathanHayward on Stack Overflow See other posts from Stack Overflow or by JonathanHayward
Published on 2010-05-21T14:17:27Z Indexed on 2010/05/21 14:20 UTC
Read the original article Hit count: 488

Let's suppose, for an example, that I want to partly clone Gmail's interface with jQuery Ajax and implement periodic auto-saving as well as sending. And in particular, let us suppose that I care about error handling, expecting network and other errors, and instead of just being optimistic I want sensible handling of different errors.

If I use the "low-level" feature of $.ajax() then it's clear how to specify an error callback, but the convenience methods of $.get(), $.post(), and .load() do not allow an error callback to be specified.

What are the best practices for pessimistic error handling? Is it by registering a .ajaxError() with certain wrapped sets, or an introspection-style global error handler in $.ajaxSetup()? What would the relevant portions of code look like to initiate an autosave so that a "could not autosave" type warning is displayed if an attempted autosave fails, and perhaps a message that is customized to the type of error?

Thanks,

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about AJAX