这是我的代码:
<html ng-app="myApp">
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.8/angular.js"></script>
</head>
<body>
<div ng-controller="MainCtrl"></div>
<script>
angular.module('myApp',[])
.controller('MainCtrl',['$scope', '$http', function($scope, $http){
console.log('I am Main controller ');
$http({
method: 'GET',
url: './testfile.rtf'
}).then(function(response){
console.log(response);
},function(error){
console.log(error);
})
}]);
</script>
</body>
</html>
这里是testfile.rtf:
{
"cities": [
{
"city": "Stockholm",
"latitud": "59",
"longitud": "18",
"id": "sthlm"
}
]
}
为什么我收到以下错误:
SyntaxError: Unexpected token \ in JSON at position 1
at JSON.parse (<anonymous>)
at fromJson (angular.js:1333)
at defaultHttpResponseTransform (angular.js:10635)
at angular.js:10726
at forEach (angular.js:321)
at transformData (angular.js:10725)
at transformResponse (angular.js:11577)
at processQueue (angular.js:16383)
at angular.js:16399
at Scope.$eval (angular.js:17682)
我在上面找不到任何错误。我将不胜感激。我在相应的文件夹中运行http-server,我尝试了几种不同的JSON文件。但是,我总是得到同样的错误!