0

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

4
  • Don't load a minimised angularjs angular.min.js, instead load angular.js and you'll be able to see a clear error Commented Apr 22, 2017 at 16:59
  • are you getting any response from $http request. Commented Apr 22, 2017 at 17:01
  • i loaded using angular.js same error.No i didnt get any response that why i am looking to solve this error Commented Apr 22, 2017 at 17:13
  • please if someone just can help me Commented Apr 22, 2017 at 17:43

1 Answer 1

1

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>

`

Sign up to request clarification or add additional context in comments.

2 Comments

I am gettin the exact error after updating angularjs version: [$http:baddata] Data must be a valid JSON object. Received: "{"records":[{"Time":"ACC 201","Count":"name"},
I have edited my code, if it is a parse error then angular.fromJson(response) will convert your response into a object.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.