我试图找出为什么$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');
});
};