CRUD with AngularJS and PHP

0

Good evening!

I have the following:

var carregarUsuario = function () {
    $http.get("buscar.php").then(function (retorno){
        console.log(retorno.data);
        $scope.usuarios = retorno.data;
    });
};
carregarUsuario();

And PHP

    error_reporting(0);
    $user = "root";
    $password = "";
    $db = "angulardb";
    $host = "localhost";
    $con = mysqli_connect("localhost", $user, $password, $db);
    if (mysqli_connect_errno()){
      echo "Erro: " . mysqli_connect_error();
      }
    $usuario = mysqli_query($con, "SELECT *  FROM users");

        header('Content-Type: application/json');
        $return = array();

        while ($dados = mysqli_fetch_assoc($usuario)) {
            array_push($return, $dados);
        }

        echo json_encode($return);

No data is being displayed on the page, or on the console. What can it be?

EDIT

When I put a print_r in my PHP code, right after while I have:

Array
(
    [0] => Array
        (
            [0] => 2
            [id] => 2
            [1] => João Silva
            [nome] => João Silva
            [2] => [email protected]
            [email] => [email protected]
            [3] => 123456
            [pass] => 123456
        )

    [1] => Array
        (
            [0] => 3
            [id] => 3
            [1] => Mario de Almeida
            [nome] => Mario de Almeida
            [2] => [email protected]
            [email] => [email protected]
            [3] => 123456
            [pass] => 123456
        )

)
    
asked by anonymous 16.01.2016 / 01:54

2 answers

0

Resolved by changing the collation of the database to UTF8

    
10.02.2016 / 23:32
1

Try to use the full resource url and display the return variable in the console.

var carregarUsuario = function () {
    $http.get("http://localhost/buscar.php").then(function (retorno){
        console.log(retorno);
        $scope.usuarios = retorno;
    });
};
carregarUsuario();
    
04.02.2016 / 13:53