Ahmad M Ibrahim
Ahmad M Ibrahim

Reputation: 309

Angularjs and Php error

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

Answers (1)

Raghavendra Rao
Raghavendra Rao

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

Related Questions