检查cookie:SyntaxError:意外的令牌u

时间:2014-11-28 14:57:34

标签: angularjs

我正在尝试查看是否设置了Cookie密钥:

if ($cookieStore.get('user')){
    $scope.session.user = $cookieStore.get('user');
    console.log($scope.session.user);
  }

我在第一行收到错误。这看起来很简单,所以我做错了什么?

完整错误:

SyntaxError: Unexpected token u
    at Object.parse (native)
    at Object.fromJson (http://localhost:8000/vendor/angular/angular.js:1139:14)
    at Object.get (http://localhost:8000/vendor/angular/angular-cookies/angular-cookies.js:172:34)
    at new <anonymous> (http://localhost:8000/js/main.js:44:33)
    at invoke (http://localhost:8000/vendor/angular/angular.js:3966:17)
    at Object.instantiate (http://localhost:8000/vendor/angular/angular.js:3977:23)
    at http://localhost:8000/vendor/angular/angular.js:7281:28
    at http://localhost:8000/vendor/angular/angular.js:6670:34
    at forEach (http://localhost:8000/vendor/angular/angular.js:332:20)
    at nodeLinkFn (http://localhost:8000/vendor/angular/angular.js:6657:11)

1 个答案:

答案 0 :(得分:2)

这是一年前被问到的,但我今天也遇到了同样的错误。

我所做的就是解决这个问题基本上是为了清除浏览器的cookie,错误就消失了。