Can't figure out why AngularJS doesn't read JSON from PHP -


i've spent hours trying figure out , browsing web, must doing wrong. every time load page it's blank. i'm trying load database mysqli angularjs. code copied w3 exercises have no idea problem is.

dbaseread.php in same folder html.

php:

 $query = "select * members";     $result = $mysqli->query($query);     $r = array();     if( $result->num_rows>0){     while($row = $result->fetch_assoc()){     $r[] = $row;     }     }       $res = json_encode($r);      header('content-type: application/json');      echo $res; 

html

<!doctype html> <html> <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script> <body>  <div ng-app="myapp" ng-controller="customersctrl">   <ul>   <li ng-repeat="x in mydata">     {{ x.name }}   </li> </ul>  </div>  <script> var app = angular.module('myapp', []); app.controller('customersctrl', function($scope, $http) {   $http.get("dbaseread.php").then(function (response) {       $scope.mydata = response.data.records;   }); }); </script>  </body> </html> 

try $scope.mydata = response.data. doesn't records property in php. inside then can put console.log(response.data) in browser console @ returned

– charlietfl

there indeed wasn't 'records' property, removing fixed issue.


Comments

Popular posts from this blog

java - pagination of xlsx file to XSSFworkbook using apache POI -

Unlimited choices in BASH case statement -

apache - How do I stop my index.php being run twice for every user -