0

I am trying to fetch some data from database but when i am returning the json encoded output to angular controller, it is not getting response data. It is showing blank. This is my controller

'use strict';

app.controller('customerController', ['$scope', '$http', function ($scope, $http) {
$http.get("data/getCustomers.php")
    .success(function(data){
        console.log(data);
        //$scope.data = data;
    })
    .error(function() {
        $scope.data = "error in fetching data";
    });
}]);

console.log is not printing anything. it is only showing blank. Here is my code to fetch data

$results = $con->query("SELECT
                    c.id,
                    c.name as companyname,
                    c.address,
                    c.postcode,
                    c.city,
                    c.country,
                    c.contactnumber,
                    c.dateadded,
                    c.plan,
                    m.companyid,
                    m.name as naam,
                    m.email,
                    a.companyid,
                    a.livemode,
                    a.srmode,
                    a.paypal
                    FROM
                    company c
                    LEFT JOIN login m ON c.id = m.companyid
                    LEFT JOIN settings a ON c.id = a.companyid
                ");

$row_cnt = $results->num_rows;

$data = array();

if($row_cnt > 0){
    while($result = $results->fetch_assoc()){
        $data[] = $result;
    }
}

echo json_encode($data);

How to get this json response and how to display using ng-repeat .

5
  • This is weird... have you tried visiting your PHP page with a web browser or sending a curl request to see the actual response ? Also maybe try adding header('Content-type: application/json') even though it should work even without it. Commented Nov 9, 2016 at 14:50
  • what shows up in the browser debugger? any errors? What does your html look like? Commented Nov 9, 2016 at 14:52
  • When i am using same php code in a php file and doing print_r, it is showing data. But when trying to print data in angular response, it is not getting anything . Commented Nov 9, 2016 at 14:53
  • No error in browser there Commented Nov 9, 2016 at 14:54
  • When i normally tried this code it is working absolutely fine and when i tried to use same code in my app it is not showing anything. stackoverflow.com/questions/26229382/… Commented Nov 9, 2016 at 14:55

0

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.