AngularJS $ http.get请求返回文件

时间:2014-11-20 01:20:28

标签: php mysql angularjs

以下代码返回实际的php文件,而不是mysql查询的结果。

app.controller('customersCrtl', ['$scope', '$http', '$timeout', function ($scope, $http, $timeout) {

    var url = "ajax/getCustomers.php";
    var response = $http.get(url);

    response.success(function (data, status, headers, config) {
        alert(status);
        $scope.list = data;
    });
    response.error(function (data, status, headers, config) {
        alert("AJAX failed!");
    });

getCustomers.php文件是:

<?php
$con=mysqli_connect("localhost","root","","exampledb");
// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

$query="select distinct c.customerName, c.addressLine1, c.city, c.state, c.postalCode, c.country, c.creditLimit from customers c order by c.customerNumber";
$result = $mysqli_query($con, $query);

$arr = array();
if($result->num_rows > 0) {
    while($row = $result->fetch_assoc()) {
        $arr[] = $row;  
    }
}
# JSON-encode the response
$json_response = json_encode($arr);

// # Return the response
echo $json_response;  
?>

我在ubuntu 14.10上使用apache2服务器。请帮忙。

0 个答案:

没有答案
相关问题