2

我尝试将登录信息保存在 cookie 中。在我的方法之后,cookies 注册了良好的数据。但是,当我重定向到下一页时,cookie 会丢失。我不明白为什么。如果有人可以解释我。

这是我的登录方法:

 $scope.Login = function()
    {
        var expireDateCookies = new Date();

        expireDateCookies.setHours(expireDateCookies.getHours() + 6);


        // default post header to url encoded content
        $http.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=utf-8';

        //variable who contains the authentication information
        var auth = $scope.auth;

        var requestGetToken = $http({ method: 'POST', url: url, headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, data: $.param({ username: auth.Login, password: auth.Password, grant_type: 'password', client_id: client_id }) });
        requestGetToken.success(function (data) {
            $cookieStore.put('access_token', data.access_token, { 'expires': expireDateCookies });
        });
        // default post header to json
        $http.defaults.headers.post['Content-Type'] = 'application/json';
        $window.location.href = '/CustomersList';
    }

谢谢你能给我的所有帮助。

4

1 回答 1

0

嘿只是想让你知道, $cookieStore 现在已经被贬低了。请检查相同的角度文档

在此处输入图像描述

尝试使用$cookies代替。这可能是您面临 cookie 清除问题的原因。

只需添加此信息,您还可以使用 HTML 5 功能的localStorage,该功能允许您将数据作为键值对存储在浏览器本身中。它没有有效期。

于 2015-10-28T06:40:35.853 回答