[Solved] Angularjs :- how to get funtion’s response using $http.get()?


In cust.php you actually need to call the function as well

<?php
   header('Content-Type: application/json');
   function testdata(){
      $str="{"employees":[{"firstName":"John", "lastName":"Doe"},{"firstName":"Anna", "lastName":"Smith"},{"firstName":"Peter", "lastName":"Jones"}]}";
      return $str;
  }
  echo testdata();
?>

EDIT: I’ve had to change your $str as well, single quote surrounding keys and values are not valid, I have changed it to double quotes ” which are valid.

As @charlietfl has stated it’s better practice for you to json_encode your JSON response instead of writing it yourself.

13

solved Angularjs :- how to get funtion’s response using $http.get()?