0

i need to access a file using $http service. But iam getting below error in Browser console.

SyntaxError: Unexpected token '
    at Object.parse (native)
    at vc (http://localhost/libFile/angular.min.js:15:313)
    at $b (http://localhost/libFile/angular.min.js:81:301)
    at http://localhost/libFile/angular.min.js:82:216
    at n (http://localhost/libFile/angular.min.js:7:322)
    at ed (http://localhost/libFile/angular.min.js:82:198)
    at c (http://localhost/libFile/angular.min.js:83:382)
    at http://localhost/libFile/angular.min.js:119:302
    at m.$get.m.$eval (http://localhost/libFile/angular.min.js:134:83)
    at m.$get.m.$digest (http://localhost/libFile/angular.min.js:131:106)

Below is html template with Angular expressions. There is no error here

<html ng-app="nameApp">
<head>
  <meta charset="utf-8">
  <script src="http://localhost/libFile/angular.min.js">
  </script>
  <script>
  var nameApp = angular.module('nameApp',[]);
    nameApp.controller('myController' , function($scope,$http)
    {
      $http.get('http://localhost/checkangular/art_1.json').success(function(data){
          $scope.arts = data;
      });
    });
  </script>
</head>
<body ng-controller="myController">
<ul>
  <li ng-repeat="art in arts">
   {{art.movie}} - {{art.mainChar}}
  </li>
</ul>
</body>
</html>

My art_1.json file.

[
  {'movie' : 'i am legand','mainChar':'Will Smith'},
  {'movie' : 'Batman Begins','mainChar' : 'Christian Bale'},
  {'movie' : 'Man of Steel', 'mainChar' : 'Henry Cavill'}
];

i browsed for finding solution and figured that i might have missed parameters in $http service or modules i did not import. In online tutorials its like they do the same and it works for them.

i am using AngularJS v1.4.0 library
Kindly suggest me a solution here

1 Answer 1

1

That's because it's invalid JSON. JSON uses " instead of ', and it doesn't end with ;.

You can use a tool like JSONLint to verify. You could also read up on JSON and its syntax. Also, just don't build JSON by hand. That's prone to a lot of errors.

Sign up to request clarification or add additional context in comments.

2 Comments

it worked.in atom editor it highlighted in red when i enclosed with ' but i ignored it.. am embarrassed right now..:)
glad you said about JsonLint

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.