Saturday, 7 September 2013

AngularJS unexpected token in fromJson()

AngularJS unexpected token in fromJson()

The following line of code:
var sid = $cookieStore.get('PHPSESSID');
is throwing this error:
SyntaxError: Unexpected token m
at Object.parse (native)
at Object.fromJson
(https://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.js:779:14)
at Object.angular.module.factory.factory.get
(https://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular-cookies.js:149:34)
at Object.getAllImages
(https://7-september.com/photoslide/js/services.js:29:36)
at new Management
(https://7-september.com/photoslide/js/controllers.js:54:18)
at invoke
(https://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.js:2902:28)
at Object.instantiate
(https://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.js:2914:23)
at $get
(https://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.js:4805:24)
at update
(https://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.js:14198:26)
at Object.$get.Scope.$broadcast
(https://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.js:8307:28)
So, I put a breakpoint at angular.js at line 779. The code there is:
777 function fromJson(json) {
778 return isString(json)
779 ? JSON.parse(json)
780 : json;
781 }
The value of json as passed into JSON.parse() is
"mnp801fap6kor50trgv4cgk7m2".
I also noticed that other things getting passed into that method usually
have two quotes around them, like ""userName"" for example.
Please help. I'm banging my head against this for a couple hours.
Or, if someone knows a better way to get the php session id out of the
cookies using Angular, that would be great, too. (Yes, I could do it using
jQuery or bare-metal JS, but I'd prefer to keep using Angular).
Thanks in advance!!!

1 comment:


  1. Come and read us!! We are moving our blog into a new site with a much more pretentious goal. We are going to teach how to be AngularJS Ninjas!!! That's right! We have taken a couple of weeks to prepare our first workshop, absolutely free!!!!


    AngularJS Certification Training in Chennai

    ReplyDelete