代码有效,Cookie myCookie
可在浏览器中访问(在Firefox中使用Firebug进行检查),但在角度代码中,我无法获取它。 AngularJS版本:1.5.7
.controller('MainCtrl', ['$scope', '$http', '$cookies', function ($scope, $http, $cookies) {
var dummy = {name: 'myuser', role: 'myrole'};
var authURL = 'http://mycustom.url';
$http({
method: 'POST',
url: authURL,
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
transformRequest: function (obj) {
var str = [];
for (var p in obj)
str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
return str.join("&");
},
data: dummy
})
.then(function successCallback(response) {
var cook = $cookies.get('myCookie');
console.log('Cookie: ' + cook); //this doesn't work.shows undefined
}, function errorCallback(response) {
console.log('ERROR');
});
}]);