Response handling of $ http.get

1

Hello, I'm looking for information in a local database with the following code:

var app = angular.module('app',[]);

app.controller('conexao',function($scope, $http){
    $scope.names = [];
    $http.get('http://localhost/angular/conect/connect.php').then(function successCalback(response){
            $scope.names = response.data;
            console.log($scope.names);
        },
        function errorCallback(response){
            console.error('Erro ' + response);
        });
});

To be displayed here:

<body ng-controller="conexao">
    <table>
        <tr ng-repeat="x in names">
            <td>{{x.nome}}</td>
            <td>{{x.idade}}</td>
            <td>{{x.cor}}</td>
        </tr>
    </table>
</body>

But all I get is an empty screen, even though the console returns:

>Object {records: Array[2]}

And this message:

  

Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience.

I want to understand what's going on and how to solve it.

    
asked by anonymous 25.11.2015 / 23:03

1 answer

2

The answer comes within a Object called 'records'. Try to do this:

$scope.names = response.data.records;

Or directly on your ng-repeat like this:

ng-repeat="x in names.records"

Regarding your other question, see if this topic resolves.

If you do not, try to use your $http as follows:

$http.get('angular/conect/connect.php').then(
    function (response){
        $scope.names = response.data;
        console.log($scope.names);
    },
    function (responseErro){
        console.error('Erro ' + responseErro);
    }
);
    
25.11.2015 / 23:04