1
預先感謝幫助! 無法顯示我從PHP返回到AngularJS站點的數據。 我已經看過關於該主題的過去主題,但他們都沒有幫助。顯示來自PHP的電話呼叫angularJS站點
我可以說的是我回來的PHP /數據看起來很好。它看起來像是我的JS文件和我的HTML文件之間的斷開。
任何想法將不勝感激。
// PHP代碼
$result = $conn->query("SELECT * FROM insights");
$insightsArray = array();
while($row = $result->fetch_array(MYSQLI_ASSOC))
{
$insightsArray[] = $row;
}
echo json_encode($insightsArray);
$conn->close();
// js代碼
var myApp = angular.module('myApp', []);
myApp.config(['$qProvider', function ($qProvider) {
$qProvider.errorOnUnhandledRejections(false);
}]);
myApp.controller('getInsights', function($scope, $http) {
$http.get("/getInsights.php")
.then(function(data){
$scope.insightsArray = data;
});
});
// HTML
<html ng-app="myApp">
<head>
<title>Get Insight</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.js"></script>
</head>
<body>
<div ng-controller="getInsights">
<ul>
<li ng-repeat="insight in insightsArray">{{insight.insighttype}}</li>
</ul>
</div>
<script src="/angularJS.js"></script>
</body>
</html>