Is there way to bind one error handler for ajax requests that performs by backbone.js?
My situation: I can get 401 (Unauthorized) at any time, so I need to show logi
You can handle this via the jQuery .ajaxSetup method. We have an identical situation (backbone app which may get a 401 error at any time) and we handle it by using jQuery's ajaxSetup in the entry point of our app:
var appView = new AppView(options);
$.ajaxSetup({
cache: false,
statusCode: {
401: function () {
appView.signIn();
}
}
});
appView.render();
Backbone.history.start({ root: config.rootUrl, pushState: true });
This approach gives global error handling without the need to extend the Backbone base classes.