0

Hi I am developing web application in angularjs. On successful login i am returning some cookies. I am trying to read cookies in success function but always i ends with undefined.

response image

   $http.post(url, sub).then(function (response) {
                 //trying to read CookieHeaders=Logintoken=63d4551a-2c09-4b08-9b4b-837f0f3806fd&LoginId=2
                    setTimeout(function () { LoginSuccess(response); }, 1000);
                }, function (error) {
                    setTimeout(function () { HideLoader(); }, 1000);
                    toastr.error($filter('translate')(error.data.msg));
                });

I tried to get inside the success function as console.log($cookieStore.get('CookieHeaders'));

It gives me undefined.

May i know is it possible to read the above cookie inside success function? Any help in this regard greatly appreciated. thank you.

Niranjan Godbole
  • 2,135
  • 7
  • 43
  • 90
  • You can refer this https://stackoverflow.com/questions/10961963/how-to-access-cookies-in-angularjs – Vivz Jul 26 '17 at 05:06
  • Thank you. I tried all the way. No luck. I have edited my code. I tried as console.log($cookieStore.get('CookieHeaders')); but it gives me undefined – Niranjan Godbole Jul 26 '17 at 05:10
  • You have to set your cookies values and then only you can get it. Idk if its possible to fetch the Set-Cookie value by this way. What you can do is set a value to a cookie variable and then next time get the value from that variable and do the operations – Vivz Jul 26 '17 at 05:17
  • Cookie values i want to set it from getcookies. May i know how can i fetch? – Niranjan Godbole Jul 26 '17 at 05:18
  • All the details are there in the above link. – Vivz Jul 26 '17 at 05:28
  • I can understand but they have not mentioned how to retrieve cookies inside ajax success call – Niranjan Godbole Jul 26 '17 at 05:29
  • Inside or outside , it doesn't matter that much, the methodology will still be the same. – Vivz Jul 26 '17 at 05:30
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/150137/discussion-between-niranjan-godbole-and-vivz). – Niranjan Godbole Jul 26 '17 at 05:31

0 Answers0