Javascript 为什么http请求调用错误回调
从服务器返回数据时,为什么http请求调用错误回调?我的代码:Javascript 为什么http请求调用错误回调,javascript,angularjs,data-binding,angularjs-scope,Javascript,Angularjs,Data Binding,Angularjs Scope,从服务器返回数据时,为什么http请求调用错误回调?我的代码: var app = angular.module('app', []); app.controller('MarkerList', ['$scope', '$http', function($scope, $http) { $http.get('http://localhost:63342/testtask/data/markers.json').then(function() { console.
var app = angular.module('app', []);
app.controller('MarkerList', ['$scope', '$http', function($scope, $http) {
$http.get('http://localhost:63342/testtask/data/markers.json').then(function() {
console.log('success')
}, function() {
console.log('error')
});
}]);
控制台日志:
SyntaxError: Unexpected token n
at Object.parse (native)
at fromJson (http://localhost:63342/testtask/app/vendor/angular.js:1033:14)
at defaults.defaults.transformResponse (http://localhost:63342/testtask/app/vendor/angular.js:6847:18)
at http://localhost:63342/testtask/app/vendor/angular.js:6822:12
at Array.forEach (native)
at forEach (http://localhost:63342/testtask/app/vendor/angular.js:300:11)
at transformData (http://localhost:63342/testtask/app/vendor/angular.js:6821:3)
at transformResponse (http://localhost:63342/testtask/app/vendor/angular.js:7491:17)
at deferred.promise.then.wrappedCallback (http://localhost:63342/testtask/app/vendor/angular.js:10689:81)
at http://localhost:63342/testtask/app/vendor/angular.js:10775:26 angular.js:9193
error
似乎您的API端点没有返回有效的json data I have data.json,包含以下内容{a:1}您确定http服务器会将此作为响应返回吗?您可以使用浏览器开发工具来检查这一点。我已经解决了这个问题。我的JSON被错误地发布了,你应该考虑如何解决这个问题作为一个答案。