w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Global error handler for Backbone.js ajax requests in Requirejs environment
define(["Backbone"], function(Backbone){
    Backbone.ajax = function() {
        // Invoke $.ajaxSetup in the context of Backbone.$
        Backbone.$.ajaxSetup.call(Backbone.$, {
            statusCode: {
                401: function(){
                    // Redirect the to the login page.
                    Backbone.history.navigate("login", true);
                },
                403: function() {
                    // 403 -- Access denied
                    Backbone.history.navigate("login", true);
                }
            }
        });
        return Backbone.$.ajax.apply(Backbone.$, arguments);
    };    
});




© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.