AngularJS 和 PHP 的增删改查
CRUD with AngularJS and PHP
我有以下代码:
var carregarUsuario = function () {
$http.get("buscar.php").then(function (retorno){
console.log(retorno.data);
$scope.usuarios = retorno.data;
});
};
carregarUsuario();
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);
控制台或页面上没有显示任何数据。我该如何解决?
更新
当您在我的 PHP 代码中放置 print_r
时,就在 while
之后,我有(在 .php 页面中):
Array
(
[0] => Array
(
[0] => 2
[id] => 2
[1] => João Silva
[nome] => João Silva
[2] => joao.silva@angular.com
[email] => joao.silva@angular.com
[3] => 123456
[pass] => 123456
)
[1] => Array
(
[0] => 3
[id] => 3
[1] => Mario de Almeida
[nome] => Mario de Almeida
[2] => mario.almeida@angular.com
[email] => mario.almeida@angular.com
[3] => 123456
[pass] => 123456
)
)
仅使用 console.log (retorno) 我有:
Object {data: "", status: 200, config: Object, statusText: "OK"}
控制台或页面上没有显示任何数据。我该如何解决?
伙计,你不能回显数组。使用 print_r(json_decode($array))
.
var carregarUsuario = function () {
$http.get("buscar.php").then(function (retorno){
console.log(retorno.data);
$scope.usuarios = retorno.data;
});
return $scope.usuarios
};
carregarUsuario();
你的功能也没有 return 什么。
问题已解决。显然错误是在数据库的整理中。银行就像拉丁语,转移到 utf8 并正常运行。谢谢
我有以下代码:
var carregarUsuario = function () {
$http.get("buscar.php").then(function (retorno){
console.log(retorno.data);
$scope.usuarios = retorno.data;
});
};
carregarUsuario();
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);
控制台或页面上没有显示任何数据。我该如何解决?
更新
当您在我的 PHP 代码中放置 print_r
时,就在 while
之后,我有(在 .php 页面中):
Array
(
[0] => Array
(
[0] => 2
[id] => 2
[1] => João Silva
[nome] => João Silva
[2] => joao.silva@angular.com
[email] => joao.silva@angular.com
[3] => 123456
[pass] => 123456
)
[1] => Array
(
[0] => 3
[id] => 3
[1] => Mario de Almeida
[nome] => Mario de Almeida
[2] => mario.almeida@angular.com
[email] => mario.almeida@angular.com
[3] => 123456
[pass] => 123456
)
)
仅使用 console.log (retorno) 我有:
Object {data: "", status: 200, config: Object, statusText: "OK"}
控制台或页面上没有显示任何数据。我该如何解决?
伙计,你不能回显数组。使用 print_r(json_decode($array))
.
var carregarUsuario = function () {
$http.get("buscar.php").then(function (retorno){
console.log(retorno.data);
$scope.usuarios = retorno.data;
});
return $scope.usuarios
};
carregarUsuario();
你的功能也没有 return 什么。
问题已解决。显然错误是在数据库的整理中。银行就像拉丁语,转移到 utf8 并正常运行。谢谢