【发布时间】:2018-05-30 13:32:53
【问题描述】:
我在 mysql 中有数据,我正在使用 url 编码将其转换为 json,
我正在使用 angularjs 来获取数据,这是我下面的 angularjs 代码
这是我的角脚本:
angular
.module('hameedApp', [])
.controller('hameedController', function($scope, $http) {
$http({
method: 'GET',
url: 'json2.php'
}).then(function(response) {
$scope.contacts = response.data;
}).catch(function(response) {
console.log('error');
})
});
这是我的 json2.php 代码:
<?php
$connect = mysqli_connect("localhost", "root", "", "recruiter");
$sql = "SELECT * FROM recruiter";
$result = mysqli_query($connect, $sql);
$json_array = array();
while($row = mysqli_fetch_assoc($result))
{
$json_array[] = $row;
}
echo print_r(json_encode($json_array));
?>
如果我在邮递员 url 中点击 json2.php,我成功地得到了 json 响应,
如果我将 {{contacts}} 放入我的 html 文件中,我成功地得到了 json 响应,但如果我使用 ng-repeat {{contact.somestuff}},我没有得到任何数据。有什么想法吗?
【问题讨论】:
-
不需要
print_r。你在{{contacts}}中看到了什么输出?也向我们展示ng-repeat -
嗨 @charlietfl 我是 hameed 朋友,他也在他的项目中工作,在 {{contacts}} 他有一些 json 响应
-
例如:{{name:sameer, age:20}} 这在 html 中正确显示
-
但如果我选择 tr(ng-repeat= 'contact in contacts') td{{contact.name}} 姓名不显示
-
创建一个重现问题的 plunker 演示
标签: php angularjs json urlencode