html - 使用 AngularJS 从 MYSQL 服务器获取数据

标签 html angularjs

我有以下代码,取自 W3schools,但现在我需要获取存在于我的“firstSchema”数据库中名为“create_table”的表中的值。请帮助我建议应该对代码进行哪些更改,以便让它在我的 table 上显示内容。

    <!DOCTYPE html>
<html >
<style>
table, th , td  {
  border: 1px solid grey;
  border-collapse: collapse;
  padding: 5px;
}
table tr:nth-child(odd) {
  background-color: #f1f1f1;
}
table tr:nth-child(even) {
  background-color: #ffffff;
}
</style>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<body>

<div ng-app="myApp" ng-controller="customersCtrl">

<table>
  <tr ng-repeat="x in names">
    <td>{{ x.Name }}</td>
    <td>{{ x.Country }}</td>
  </tr>
</table>

</div>

<script>
var app = angular.module('myApp', []);
app.controller('customersCtrl', function($scope, $http) {
   $http.get("http://www.w3schools.com/angular/customers_mysql.php")
   .then(function (response) {$scope.names = response.data.records;});
});
</script>

</body>
</html>

最佳答案

您的代码似乎可以很好地实际显示某些内容,但显然您需要修改 ng-repeat 以反射(reflect)您从数据库中获取的数据。我认为你缺少的是应用程序的服务器端方面,你需要用你自己的端点替换对 w3schools 端点的调用,在那里你可以查询你的数据库并返回你想要的任何东西......

$http.get("yourappsomewhere/query_database_in_here.php")
.then(function (response) {$scope.yourdata = response.data;});

关于html - 使用 AngularJS 从 MYSQL 服务器获取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35195824/

相关文章:

angularjs - 如何从 Angular cli 调用 Passportjs(node) API?

javascript - 音频无法播放 - JS -

javascript - 下拉值更改时更新 html 表

html - SVG 在 IE 中无法正确缩放 - 有额外的空间

javascript - 使用 Controller 中对象的位置 x,y 创建动态网格或表格 - bootstrap、AngularJS

angularjs - Select 元素的奇怪行为取决于 DOM 顺序

javascript - 在 AngularJS 中加载本周的数据

html - 使用 .live() 处理 jQuery Checkbox 事件

html - CSS 关于两列布局

javascript - angularjs `$digest`什么时候触发?