0

I'm following this tutorial to retrieve data from a database. The retrived data from the server is a json array and it contains these two objects:

[{"_id":{"$oid":"5ae81566f3a9bd1fe8002d34"},"Customer_Name":"cXQzbXlUeHRVckFvVGpoVUQxaHNoQT09","Responsiple_User":"Wjc0TFpMbUtyUlo1bGptZ1RCOG84Zz09","Phone_Number":"Wjc0TFpMbUtyUlo1bGptZ1RCOG84Zz09","ID_Number":"Wjc0TFpMbUtyUlo1bGptZ1RCOG84Zz09","Sale":"Wjc0TFpMbUtyUlo1bGptZ1RCOG84Zz09","Resposible_Sales":"Wjc0TFpMbUtyUlo1bGptZ1RCOG84Zz09","City":"Wjc0TFpMbUtyUlo1bGptZ1RCOG84Zz09","Job":"Wjc0TFpMbUtyUlo1bGptZ1RCOG84Zz09","Monhthly_Income":"Wjc0TFpMbUtyUlo1bGptZ1RCOG84Zz09","Number_Of_Months":"SVFxZVJkWG0vaUhxSUxFNzdrWjZCZz09","Monthly_installment_of_the_client":"Wjc0TFpMbUtyUlo1bGptZ1RCOG84Zz09","First_Payment":"Wjc0TFpMbUtyUlo1bGptZ1RCOG84Zz09","Bank":"Wjc0TFpMbUtyUlo1bGptZ1RCOG84Zz09","Financial_Situation":"Wjc0TFpMbUtyUlo1bGptZ1RCOG84Zz09","Account":"Wjc0TFpMbUtyUlo1bGptZ1RCOG84Zz09","Notes":"Wjc0TFpMbUtyUlo1bGptZ1RCOG84Zz09","Date":"2018-05-01 09:21:10"},{"_id":{"$oid":"5ae8157ff3a9bd1fe8002d36"},"Customer_Name":"aGxveGF1SGxKWXpFajgzSGI0RmE0QT09","Responsiple_User":"Wjc0TFpMbUtyUlo1bGptZ1RCOG84Zz09","Phone_Number":"Wjc0TFpMbUtyUlo1bGptZ1RCOG84Zz09","ID_Number":"Wjc0TFpMbUtyUlo1bGptZ1RCOG84Zz09","Sale":"Wjc0TFpMbUtyUlo1bGptZ1RCOG84Zz09","Resposible_Sales":"Wjc0TFpMbUtyUlo1bGptZ1RCOG84Zz09","City":"Wjc0TFpMbUtyUlo1bGptZ1RCOG84Zz09","Job":"Wjc0TFpMbUtyUlo1bGptZ1RCOG84Zz09","Monhthly_Income":"Wjc0TFpMbUtyUlo1bGptZ1RCOG84Zz09","Number_Of_Months":"Wjc0TFpMbUtyUlo1bGptZ1RCOG84Zz09","Monthly_installment_of_the_client":"Wjc0TFpMbUtyUlo1bGptZ1RCOG84Zz09","First_Payment":"Wjc0TFpMbUtyUlo1bGptZ1RCOG84Zz09","Bank":"Wjc0TFpMbUtyUlo1bGptZ1RCOG84Zz09","Financial_Situation":"Wjc0TFpMbUtyUlo1bGptZ1RCOG84Zz09","Account":"SVFxZVJkWG0vaUhxSUxFNzdrWjZCZz09","Notes":"Wjc0TFpMbUtyUlo1bGptZ1RCOG84Zz09","Date":"2018-05-01 09:21:35"}]

I modified the code in the tutorial to display only the json data in the table. The problem is that I keep getting the issue of response is not defined. Below is my code

<!DOCTYPE html>  
 <!-- index.php !-->  
 <html>  
      <head>  
           <title>test</title>  
           <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />  
           <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>  
      </head>  
      <body>  
           <br /><br />  
           <div class="container" style="width:500px;">  
                <h3 align="center">AngularJS Tutorial with PHP - Fetch / Select Data from Mysql Database</h3>  
                <div ng-app="myapp" ng-controller="usercontroller" ng-init="displayData()">  

                     <table class="table table-bordered">  
                          <tr>  
                               <th>First Name</th>  
                               <th>Last Name</th>  
                          </tr>  
                          <tr ng-repeat="x in names">  
                               <td>{{x.City}}</td>  
                               <td>{{x.last_name}}</td>  
                          </tr>  
                     </table>  
                </div>  
           </div>  
      </body>  
 </html>  
 <script>  
 var app = angular.module("myapp",[]);  
 app.controller("usercontroller", function($scope, $http){  

      $scope.displayData = function(){  
      alert ("s");
           $http.get("data.php",$scope.names = response ).success(function(response){});  

      }  
 });  
 </script>  
4
  • $scope.names = response....response is not defined. Commented May 1, 2018 at 7:24
  • Please check the link in the description Commented May 1, 2018 at 7:26
  • If you would expect people to help you you are expected to provide them with all info so that it is easy to help. And not ask them to go check links. Commented May 1, 2018 at 7:27
  • what ever the link says does not matter. you are trying to pass response to get() before being declare which leads to the error. Commented May 1, 2018 at 7:29

1 Answer 1

1

Change your function body and get request to this

$http.get("data.php").success(function(response){
    $scope.names = response;
});  
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.