1

Appreciate the help up-front! Having trouble displaying the data I get back from PHP onto an AngularJS site. I've looked at past threads on the topic, but none of them have helped.

What I can say is that the PHP/data I am getting back looks fine. It just looks like there is a disconnect between maybe my JS file and my HTML file.

Any thoughts would be much appreciated.

//PHP CODE

$result = $conn->query("SELECT * FROM insights");

$insightsArray = array();
while($row = $result->fetch_array(MYSQLI_ASSOC))
{

$insightsArray[] = $row;

}

echo json_encode($insightsArray);

$conn->close();

//JS CODE

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>
0

1 Answer 1

1

Change your controller like this. You have to access the data property of your response.

myApp.controller('getInsights', function($scope, $http) {
   $http.get("/getInsights.php")
   .then(function(data){
       $scope.insightsArray = data.data;
   });

});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.