Thomas
Thomas

Reputation: 247

angularJS read response cookie parameter empty

If I made a request on my server with $http I get the following response:

Request URL:http://www.test.tst/login
Request Method:GET
Status Code:200 OK
Request Headersview source
Accept:application/json, text/plain, */*
Accept-Encoding:gzip,deflate,sdch
Accept-Language:de-DE,de;q=0.8,en-US;q=0.6,en;q=0.4
Connection:keep-alive
Cookie:JSESSIONID=349AD3AC797C6AB28121ADA1766FF4A2
Host:www.test.tst

i implemented it that way:

$scope.checkToken = function () {
            $http({method: 'GET', url: 'http://www.test.tst/login', params: {'action.code': 'LINK', 'linkparameter': $rootScope.token}}).
                success(function (data, status, headers, config) {
                    console.log($cookieStore.get('JSESSIONID'));
                }).
                error(function (data, status, headers, config) {
                    $location.path("/login");
                });
        }

can anybody tell me, why $cookieStore.get('JSESSIONID') is always undefined?

the cookie domain is the same as the domain my request is coming from.

Upvotes: 4

Views: 2263

Answers (1)

Pascal Le Merrer
Pascal Le Merrer

Reputation: 5981

You should use the $cookie service, and not the $cookieStore $cookie provides access to the browser cookies; while $cookieStore allows you to store and retrieve values.

It means to access the cookies set by the server, you will use $cookie.$cookieStore.get() will allow you to access values you stored in your application, using $cookieStore.set() Just replace $cookieStore with $cookie in your code.

Upvotes: 1

Related Questions