dsaxw4201 2016-05-20 09:40
浏览 72

使用php无法使用angular $ http服务显示数据?

im building a project with angular,i have a html form that sends data to "customers" table in MYSQL. now i want to show the data of "customers" table. this is my code that i tried to get that data but its not working. can anyone help?

php code:

<?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;
  echo $sql_statement;
  ?>

controller:

"use strict";
var app = angular.module('dataSystem',[]);
app.controller('customerCardsCtrl',function($scope,$route,$location,$http){
    $http({method:'GET', url:'api/get-allCustomers.php'}).success(function(response){
        $scope.customers = response.data;
      });
    });
});

html code:

<!DOCTYPE html>
<html >
<head>
    <title></title>
</head>
<body>


    <div>
      <table ng-controller="customerCardsCtrl" >
        <tr ng-repeat="x in customers">
        <td> {{ x.customer_id}} </td>
        <td>{{ x.first_name }}</td>
        <td>{{ x.last_name }}</td>
        <td> {{ x.id}} </td>
        <td> {{ x.city}} </td>
        <td> {{ x.adress}} </td>
        <td> {{ x.phone}} </td>
        <td> {{ x.email}} </td>
        <td> {{ x.fax}} </td>
        <td> {{ x.referrer}} </td>
        <td> {{ x.comments}} </td>

        </tr>
        </table>
    </div>
</body>
</html>
  • 写回答

1条回答 默认 最新

  • dpjjmo3079 2016-05-20 10:38
    关注

    use this code instead

    "use strict";
    var app = angular.module('dataSystem',[]);
    app.controller('customerCardsCtrl',function($scope,$route,$location,$http){
      $http({method:'GET', url:'api/get-allCustomers.php'})
        .then(function(response){
               $scope.customers = response.data;
           }, function(response){
               console.log(response)
           });
    });
    
    评论

报告相同问题?

悬赏问题

  • ¥15 软件工程用例图的建立(相关搜索:软件工程用例图|画图)
  • ¥15 如何在arcgis中导出拓扑关系表
  • ¥15 处理数据集文本挖掘代码
  • ¥15 matlab2017
  • ¥15 在vxWorks下TCP/IP编程,总是connect()报错,连接服务器失败: errno = 0x41
  • ¥15 AnolisOs7.9如何安装 Qt_5.14.2的运行库
  • ¥20 求:怎么实现qt与pcie通信
  • ¥50 前后端数据顺序不一致问题,如何解决?(相关搜索:数据结构)
  • ¥15 基于蒙特卡罗法的中介效应点估计代码
  • ¥15 罗技G293和UE5.3