如何使用angularjs$http从phpmyadmin表检索数据?

如何使用angularjs$http从phpmyadmin表检索数据?,php,angularjs,Php,Angularjs,我可以向表发送数据,但无法检索数据。这是 我试过的代码。我想在html页面中显示表的详细信息。 我不明白为什么这个代码不起作用。有人能帮忙吗 php代码: <?php $con = mysqli_connect('localhost','root','','hamatkin'); if(!$con){ die("couldnt connect".mysqli_error); } $query = "SELECT * FROM customer

我可以向表发送数据,但无法检索数据。这是 我试过的代码。我想在html页面中显示表的详细信息。 我不明白为什么这个代码不起作用。有人能帮忙吗

php代码:

<?php
    $con = mysqli_connect('localhost','root','','hamatkin');
    if(!$con){
        die("couldnt connect".mysqli_error);
    }
    $query = "SELECT * FROM customers";
    $result = $con->query($query);
    $r = array();
    if( $result->num_rows>0){
        while($row = $result->fetch_assoc()){
            $r[] = $row;
        }
    }
    $res = json_encode($r);
    echo $res;
?>
HTML:


{{x.customer_id}
{{x.名字}
{{x.last_name}
{{x.id}
{{x.city}
{{x.address}
{{x.phone}}
{{x.email}
{{x.fax}
{{x.referer}}
{{x.comments}}
请再试一次

 <?php
      $con = mysqli_connect('localhost','root','','hamatkin');
      if(!$con){
      die("couldnt connect".mysqli_error);
      }
      $query = "SELECT * FROM customers";
      $result = $con->query($query);
      $r = array();
      if( $result->num_rows>0){
      while($row = $result->fetch_assoc()){
      $r[] = $row;
      }
      }
      $res = json_encode($r);
      echo $res;
die();
      ?>


添加模具();函数

您必须使用
响应。数据
而不仅仅是
响应

重要:

$http legacy promise方法的成功和错误已被删除 不赞成。改用标准then方法。如果 $httpProvider.useLegacyPromiseExtensions设置为false,则这些 方法将抛出$http/legacy错误

为了提高可读性,您还可以为get请求使用较短的版本:

$http.get('get-allCustomers.php').then(function(response){
    $scope.customers = response.data;
}, function(response){
   //Your errorhandler
});

php代码是=>get-allCustomers.php的代码使用firebug/developers工具中的Net选项卡了解ajax调用是否完成,并查看添加的iti中是否有错误,但仍然相同
 <?php
      $con = mysqli_connect('localhost','root','','hamatkin');
      if(!$con){
      die("couldnt connect".mysqli_error);
      }
      $query = "SELECT * FROM customers";
      $result = $con->query($query);
      $r = array();
      if( $result->num_rows>0){
      while($row = $result->fetch_assoc()){
      $r[] = $row;
      }
      }
      $res = json_encode($r);
      echo $res;
die();
      ?>
"use strict";
var app = angular.module('dataSystem',[]);
app.controller('customerListCtrl',function($scope,$http){
    $http({method:'GET', url:'get-allCustomers.php'}).then(function(response){
        $scope.customers = response.data;
    }, function(response){
       //Your errorhandler
    });
});
$http.get('get-allCustomers.php').then(function(response){
    $scope.customers = response.data;
}, function(response){
   //Your errorhandler
});