1
我是角js中的新角色,我想使用php從數據庫中獲取數據。我嘗試下面的代碼。使用php從角度js的數據庫中獲取數據
<html>
<head>
<script src = "http://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular.min.js"></script>
<script>
var myApp = angular.module('myApp',[]);
myApp.controller('studentController', ['$scope','$http', function ($scope,$http) {
var url = "ajax.php";
$http.get(url).success(function(response) {
$scope.students = response;
});
}]);
</script>
</head>
<body>
<div ng-app = "myApp" ng-controller = "studentController">
<table>
<tr>
<th>Name</th>
</tr>
<tr ng-repeat = "student in students">
<td>{{ student.Name }}</td>
</tr>
</table>
</div>
</body>
</html>
ajax.php 這個代碼給我下面的輸出:
[{"Name":"Mahesh","Roll":"122222"},{"Name":"ajay","Roll":"444433"}]
但我不能夠顯示在前端...謝謝。
<?php
$con = mysqli_connect("localhost","root","","adworld");
$res= mysqli_query($con,"SELECT * FROM students");
$result = array();
while($row=mysqli_fetch_assoc($res)){
$result[] = $row;
}
echo json_encode($result);
?>
你需要在你的應用程序註冊您的控制器 - 'myApp.controller( 「studentController」,[ '$範圍' ,函數($範圍){ $ scope.greeting ='Hola!'; }]);' – messerbill
https://docs.angularjs.org/guide/controller – messerbill
@messerbill:不工作.... –