Wie behandeln http 302-Antwort in angularjs

Ich habe ein java-filter, die überprüft, session-Attribut username. Wenn username null ist, dann redirect Pfad /login.Habe ich Zugriff auf Pfad /index.html wenn username null ist, bekam ich einen HTTP-code 302, so dass ich hinzufügen interceptor in angularjs. Aber ich access /index.html bekam eine Fehlermeldung, wenn username null ist.

JS:

var testApp = angular.module('testApp', [ 'ngRoute', 'myApp' ]);

testApp.config([ '$routeProvider', function($routeProvider) {
	$routeProvider.when('/anchor/historyAttendance/:uid',{
        templateUrl : 'anchor/historyAttendance.html',
        controller : 'AnchorHistoryAttendanceCtrl'
    }).when('/anchor/list', {
        templateUrl : 'anchor/list.html',
        controller : 'AnchorListCtrl'
    }).otherwise({
		redirectTo : '/'
	});
} ]);

var app = angular.module('myApp', [ 'ngTable', 'ngFileUpload', 'ngDialog' ,'ui.colorpicker', 'ngCsv', 'ngSanitize'],function ($provide,$httpProvider) {
    //register the interceptor as a service
    $provide.factory('myHttpInterceptor', function($q) {
        return {
            //optional method
            'request': function(config) {
                //do something on success
                console.log(config);
                return config;
            },
            //optional method
            'requestError': function(rejection) {
                //do something on error
                console.log(rejection);
                return $q.reject(rejection);
            },
            //optional method
            'response': function(response) {
                //do something on success
                console.log(response);
                return response;
            },
            //optional method
            'responseError': function(rejection) {
                //do something on error
                console.log(rejection);
                return $q.reject(rejection);
            }
        };
    });

    $httpProvider.interceptors.push('myHttpInterceptor');
});

app.directive('fontColor', function () {
    return {
        restrict: 'E',
        scope: {},
        replace: false,
        template: '<div color-picker default-color="#ff0000" class="font-color" ng-style="{\'background-color\': selectedFontColor}"></div>',
        link: function (scope) {
            scope.selectedFontColor = '#f00';
            scope.$on('colorPicked', function (event, color) {
                scope.selectedFontColor = color;
            });
        }
    }
});

der Fehler in chrome so:Wie behandeln http 302-Antwort in angularjs

InformationsquelleAutor Ryanqy | 2016-05-23
Schreibe einen Kommentar