角& HTML代碼:意外標記,在JSON在位置23
<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<body>
<div ng-app="myApp" ng-controller="myCtrl">
<p>Today's welcome message is:</p>
<h1>{{ myWelcome }}</h1>
</div>
<p>The $http service requests a page on the server, and the response is set as the value of the "myWelcome" variable.</p>
<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope, $http) {
$http({
method: "GET",
url: "http://localhost/dustbin/uxo_data/leaderboard.php"
}).then(function mySucces(response) {
$scope.myWelcome = response.data;
}, function myError(response) {
$scope.myWelcome = response.statusText;
});
});
</script>
</body>
</html>
PHP返回:
{"total":"4","phn":"1"},{"total":"1","phn":"2"}
錯誤:
angular.min.js:107 SyntaxError: Unexpected token , in JSON at position 23
什麼在上面的代碼中的錯誤,我在後端使用angular和php作爲rest-api
返回的數據是無效的JSON。至少一個周圍的'[]'會丟失。 – Sirko
在php中使用'json_encode'來返回數組。 –
@sachilaranawaka你可以添加相關的PHP代碼嗎?至少你使用'json_encode()'錯誤的方式。 – Sirko