i'm trying to execute a promise in angular, this is my service code :
var carsService = function ($http, $q, $log, $rootScope) {
var service = this;
service.getInfo = function () {
var defer = $q.defer();
$http.get($rootScope.endPoint + 'cars.php?load=t')
.success(function (data) {
defer.resolve(data);
})
.error(function (data, status, headers, config) {
defer.reject({
n: 1000,
msj: 'some error msg'
});
$log.log(data + ' ' + status + ' ' + headers + ' ' + config);
});
return defer.promise;
};
};
and this is how i called from my controller :
CarsService.getInfo()
.then(function (data) {
console.log(data);
}, function (err) {
swal("ERROR", "some error msg.", "error");
}
);
and this is my cars.php file :
<?php
var $r = array('a'=>1,'b'=>2);
print json_encode($r);
?>
what i'm expecting is the console print an array , but what i get is the php code printed.
PHP is running :
I tried with POSTMAN too :
Any ideas guys ???? thanks ...