我正在使用ajax从数据库中获取数据。数据库中有大约20条记录。这是获取数据的PHP代码。
$query = "SELECT user_id,website,emailid FROM job_posting where uid = ? order by date DESC";
$result = $mysqli->prepare($query);
$result ->bind_param("i",$uid);
$result->execute();
$result->store_result();
$result->bind_result($user_id,$website,$emailid);
if($result->num_rows >0){
while ($result->fetch()) {
$website = $website;
$emailid = $emailid;
$user_id = $user_id;
$data['content'][] = array(
'website' => $website,
'emailid' => $emailid,
'user_id' => $user_id,
);
}
$data['success'] = 'true';
}
echo json_encode($data);
}
以上代码工作正常。我可以看到json格式的数据。以下示例。
{"content":[{"website":"test.com","emailid":"none@none.com","user_id":1},{"website":"test.com","emailid":"none@none.com","user_id":2},{"website":"test.com","emailid":"none@none.com","user_id":3}],"success":"true"}
现在我想在网页中按角度显示此数据。
角度代码:
$http({
url: 'get_details.php',
method: "GET",
params: {uid: uid}
})
.success(function(data) {
if (data.success) {
}
请告知如何在div中显示数组数据。
<div class="col-md-12>
Need to show website, email id and user id in this div.
</div>
答案 0 :(得分:1)
你应该使用然后成功。成功和错误已被弃用,将在v1.6.0中删除。
$http({
url: 'get_details.php',
method: "GET",
params: {uid: uid}
})
.then(function(data) {
$scope.data = data.data.content
}
并在div
<div class="col-md-12 ng-repeat="x in data >
{{x.emailid}} - {{x.userid}}
</div>
答案 1 :(得分:1)
它应该是这样的。(但更好地使用then
函数而不是success
)
$http({
url: 'get_details.php',
method: "GET",
params: {uid: uid}
})
.success(function(data) {
$scopemyData = data.content;
}
并在视野中
<div ng-repeat="data in myData">
<span>{{data.website}}</span>
<span>{{data.emailid}}</span>
<span>{{data.user_id}}</span>
</div>