Reputation: 309
This is my script
<script>
var app = angular.module('myApp', []);
app.controller('customersCtrl', function($scope, $http) {
$http.get("http://ip/ss.php")
.then(function (response) {$scope.names = response.data.records;});
});
</script>
Help me please
EDIT: This is the exact error
Error: [$http:baddata] Data must be a valid JSON object. Received: "{"records":[{"Time":"ADV 360","Count":"name"},{"Time":"CCE 401","Count":"name"}. Parse error: "{"description":"Invalid character","number":-2146827274,"stack":"SyntaxError: Invalid character\n at fromJson (https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.js:1431:3)\n at defaultHttpResponseTransform (https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.js:11175:11)\n
Upvotes: 0
Views: 1332
Reputation: 130
Try to use the following code. This will catch the exact error message in response. Or if you are getting response then check it in console as follows.
<script>
app.controller('customersCtrl', function($scope, $http) {
$http.get("http://ip/ss.php")
.then(function (response) {
angular.fromJson(response);
console.log(JSON.sringify(response));
$scope.names = response.data.records;},
function(error) {console.log(JSON.sringify(error));}
);
});
</script>
`
Upvotes: 1