I am trying to grab an echo from a php script that spits out JSON.
<?php
$arr = array('a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5);
echo json_encode($arr);
?>
What I have in my angular code is the following: 'use strict';
app.factory('HttpRequestService', function($http) {
var HttpRequestService = {
async: function() {
var promise = $http.get('/test.php').then(function (response) {
return response.data;
});
return promise;
},
load: function() {
console.log('helloo');
}
};
return HttpRequestService;
});
And then in my service I have :
HttpRequestService.async().then(function(data) {
console.log('data is : ' + data);
});
but this literary spits the whole php script and not just the echo data:
console :
data is : <?php
$arr = array('a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5);
echo json_encode($arr);
?>
Any ideas why this is happening? Thanks!