HELP: http.get does not get the json result from a php file

I’ve been stuck on this for quite a long time now. I can’t figure out what’s wrong, and I am getting nowhere. I would really appreciate some advise!


  • Instead of the json result (ex: {“a”:1,“b”:2,“c”:3}) I get the whole php file ( I know this because in the index.html file, I tested it with {{ items }} )
  • When I load the php file instead of the index.html, I see json though
  • The HTTP status of the php file is 302 also…
  • I’ve tried putting the Context-type: application/json in the php file and setting cache to false

.controller('EntryController', ["$scope", "$http", function($scope, $http) { $scope.items = []; $http({ method: 'GET', cache: false, url: '../services/getItemtest.php' }) .then(function(response) { $scope.items =; }, function(response){ $scope.items = 'Could not retrieve Items'; }); ...

<?php header("Content-Type: application/json"); $result = array('a'=>1, 'b'=>2, 'c'=>3); echo json_encode($result); ?>

The fact that you have a php page within your ionic app…makes me scared :fearful:. I mean, how does that even work?

Sorry, I am new to this. Can you explain why it’s scary/wrong?

For PHP to do anything, it needs to be fed to a PHP interpreter. Those tend to live on servers, not inside HTML5 applications.

1 Like

Okay, ionic was running live-reload server and I thought that was good enough, but from what you mentioned, I guess it doesn’t have the PHP interpreter.

please use php as a web services with data as json format. why you want php page using http . If want use inappbrower cordova plugin .

may be problem of json array. check it