The view for an overview (root.html) of MySQL data doesn't show data. Opening /php/overview.php however indicates that the data could be fetched correctly:
MySQL数据的概述(root.html)视图不显示数据。但是打开/php/overview.php表示可以正确获取数据:
Connection to MySQL server successful. [{"Job_title":"flash","Job_id":"doggg"},{"Job_title":"ad34","Job_id":"teeee"}]
连接MySQL服务器成功。 [{ “JOB_TITLE”: “闪”, “JOB_ID”: “doggg”},{ “JOB_TITLE”: “AD34”, “JOB_ID”: “teeee”}]
root.html
<table class="setup-table">
<tr>
<td>Job title</td>
<td>Job ID</td>
</tr>
<tr data-ng-repeat="campaign in campaigns">
<td>A {{campaign.Job_title}}</td>
<td>B {{campaign.Job_id}}</td>
</tr>
</table>
controller.js (Note that the alert "It WORKED (DELETE Later)" shows up, but the table in the view is empty:
controller.js(注意警告“It WORKED(DELETE Later)”出现,但视图中的表是空的:
ctr.controller
('RootCtrl', ['$scope', '$routeParams', '$http', function($scope, $routeParams, $http)
{
$http.get("php/overview.php")
.then(function successCallback(response){
console.log(response);
$scope.campaigns = response.data;
alert("It WORKED (DELETE ME)");
}
, function errorCallback(response) {
$scope.campaigns = "error in fetching data";
alert("DID NOT WORK ");}
)
;}
]);
overview.php
<?php
include_once('db.php');
$query = "SELECT Job_title, Job_id FROM campaign";
$result = $connect->query($query);
$data = array();
while ($row = mysqli_fetch_array($result,MYSQL_ASSOC)) {
$data[] = $row;
}
print json_encode($data);
mysql_close($connect);
?>
1 个解决方案
#1
1
Most of the time when you get a server route you receive a full response object in reply rather than just the requested data, so changing the section of your code that makes this call to look like this:
大多数情况下,当您获得服务器路由时,您会收到一个完整的响应对象而不仅仅是请求的数据,因此更改代码部分使得此调用看起来像这样:
{
$http.get("php/overview.php")
.success(function(response){
console.log(response);
$scope.campaigns = response.data;
alert("It WORKED (DELETE Later)");
})
.error(function() {
$scope.campaigns = "Could not fetch data";
alert("DID NOT WORK (DELETE Later");
});
}
should do the trick. I also added a console.log call so you can inspect the response.
应该做的伎俩。我还添加了一个console.log调用,以便您可以检查响应。
Note: success and error are deprecated. It's recommended that you use .then() in response to a $http call. The refactoring is very minor.
注意:不推荐使用成功和错误。建议您使用.then()来响应$ http调用。重构非常小。
#1
1
Most of the time when you get a server route you receive a full response object in reply rather than just the requested data, so changing the section of your code that makes this call to look like this:
大多数情况下,当您获得服务器路由时,您会收到一个完整的响应对象而不仅仅是请求的数据,因此更改代码部分使得此调用看起来像这样:
{
$http.get("php/overview.php")
.success(function(response){
console.log(response);
$scope.campaigns = response.data;
alert("It WORKED (DELETE Later)");
})
.error(function() {
$scope.campaigns = "Could not fetch data";
alert("DID NOT WORK (DELETE Later");
});
}
should do the trick. I also added a console.log call so you can inspect the response.
应该做的伎俩。我还添加了一个console.log调用,以便您可以检查响应。
Note: success and error are deprecated. It's recommended that you use .then() in response to a $http call. The refactoring is very minor.
注意:不推荐使用成功和错误。建议您使用.then()来响应$ http调用。重构非常小。