$ cookies.get无法访问域

时间:2018-05-07 18:58:07

标签: angularjs cookies routes

我试图找出为什么$cookies.get无法在实时域上工作。在本地服务器上它工作正常,并将我重定向到特定页面。但是在实时服务器上,如果我控制$ cookies.get('key'),我会得到undefined

为什么会发生这种情况呢?

$scope.login = function () {
    $http({
        method: 'POST',
        url: api_base_url + '/user/login',
        data: $.param($scope.loginData),
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
        }
    }).then(function (data) {
        toaster.pop('success', "", "Successfully Logged In", null, 'trustedHtml');
        $cookies.put('auth_token', data.data.access_token);
        $cookies.put('id', data.data.id);
        $cookies.put('role', data.data.role);
        $cookies.put('payment', data.data.payment);
        console.log($cookies.get('auth_token'));
        console.log($cookies.get('id'));
        console.log($cookies.get('role'));
            console.log($cookies.getAll());

        if ($cookies.get('auth_token') && $cookies.get('id') && $cookies.get('role')) {
            // console.log("Successfully Getting Aut role status and ID");
            $rootScope.auth_token = $cookies.get('auth_token');
            $rootScope.id = $cookies.get('id');
            $rootScope.role = $cookies.get('role');
            $rootScope.is_loggedin = true;
            $rootScope.payment = $cookies.get('payment');
            // If page refresh i was losing he logged in value so i put it here
        }
        if (data.data.role == 20) {

            $location.path('/dash');
        }
        if (data.data.role == 10) {

            $location.path('/cust-dash');
        }

    }, function (error) {
        if (error.data.password)
            toaster.pop('error', "", error.data.password, null, 'trustedHtml');
        if (error.data.email)
            toaster.pop('error', "", error.data.email, null, 'trustedHtml');

    });
};

0 个答案:

没有答案