SyntaxError: Unexpected token o at Object.parse (native) AngularJS

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-30 08:08:00

I think data returned is already in JSON, no need of JSON.parse(), unless it in string format.

$scope.products= data;

Why you using JSON.parse in two times?

 var myjson = JSON.parse(data);
  $scope.products = JSON.parse(myjson);

You have already parse the data object,So then why you parsing another one time?

also i think your data is return Json result, so you don't need to parse the object

just use this

$scope.products = data;

Your variable myjson is already a valid JavaScript Object. You do not have to use JSON.parse on it.

Mohammad nasim

Simple solution, just use an absolute url:

var url = 'http://demo/app/pricefilessetup/grid.asmx/getGridJson';

Instead of using var url = 'app/pricefilessetup/grid.asmx/getGridJson'; I have checked.

In my case it was string literal being passed in as parameter to JSON.parse().

For Example JSON.parse('asdf') would throw an error Uncaught SyntaxError: Unexpected token a.

With specific case, in Single page angular application, the access token was being passed to the JSON.parse() and clearing the cookies in browser solved the problem for me.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!