Html 使用AngularJS从MYSQL服务器获取数据
我有以下代码,取自W3schools,但现在我需要获取“firstSchema”数据库中名为“create_table”的表中的值。请帮助我,建议应该对代码进行哪些更改,以使其显示我表格上的内容Html 使用AngularJS从MYSQL服务器获取数据,html,angularjs,Html,Angularjs,我有以下代码,取自W3schools,但现在我需要获取“firstSchema”数据库中名为“create_table”的表中的值。请帮助我,建议应该对代码进行哪些更改,以使其显示我表格上的内容 <!DOCTYPE html> <html > <style> table, th , td { border: 1px solid grey; border-collapse: collapse; padding: 5px; } table t
<!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>
表,th,td{
边框:1px纯灰;
边界塌陷:塌陷;
填充物:5px;
}
表tr:第n个子项(奇数){
背景色:#f1f1;
}
表tr:第n个子项(偶数){
背景色:#ffffff;
}
{{x.Name}
{{x.国家}
var-app=angular.module('myApp',[]);
app.controller('customersCtrl',函数($scope,$http){
$http.get(“http://www.w3schools.com/angular/customers_mysql.php")
.then(函数(响应){$scope.names=response.data.records;});
});
您的代码对于实际显示某些内容似乎很好,但显然您需要修改ng repeat以反映从数据库中获取的数据。我认为您缺少的是应用程序的服务器端方面,您需要将对w3schools端点的调用替换为您自己的端点,在那里您可以查询您的数据库并返回您想要的任何内容
$http.get("yourappsomewhere/query_database_in_here.php")
.then(function (response) {$scope.yourdata = response.data;});
谢谢你,我有预感,这就是我错的地方。