I am getting the following error while fetching data from my json file.
Error:
SyntaxError: Unexpected token '
at Object.parse (native)
at uc (http://localhost/json/angularjs.js:15:480)
at Zb (http://localhost/json/angularjs.js:82:229)
at http://localhost/json/angularjs.js:83:143
at m (http://localhost/json/angularjs.js:7:322)
at cd (http://localhost/json/angularjs.js:83:125)
at d (http://localhost/json/angularjs.js:84:380)
at http://localhost/json/angularjs.js:118:334
at n.$eval (http://localhost/json/angularjs.js:132:452)
at n.$digest (http://localhost/json/angularjs.js:129:4
Here is my code:
var test=angular.module('testapp', []);
test.controller('HelloController',function ($scope,$http) {
console.log('hello');
$http({
method: 'GET',
url: 'data.json',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
}).then(function successCallback(response){
},function errorCallback(response) {
//$state.go('/',{}, { reload: true });
});
// Do something with myService
});
data.json:
[
{
'id':1,
'email':'[email protected]',
'name':'Rahul'
},
{
'id':2,
'email':'[email protected]',
'name':'Ram'
},
{
'id':3,
'email':'[email protected]',
'name':'praveen'
}
]
How can I get all the data?
$httpcall, as you're not POST-ing anything./data.jsonthis error is not coming but can not get the proper file.When i did againprojectfoldername/data.jsonagain wrong path is also coming.