2
Good afternoon
I need to pass data via post using Angularjs for a php api the data appears in the controller but not in the PHP api.
if( isset($_REQUEST['mes']) ) {
$mes = $_REQUEST['mes'];
} else {
$mes = date('m');
}
In the controller I visualize the form data (month and origin ):
.controller('AcpBuscaCtrl', function($scope, ApiAcp, $ionicLoading, $timeout, $http, $q) {
$scope.pesquisaAcp = function(data ) {
$scope.mes = data.mes;
$scope.origem = data.origem;
$ionicLoading.show({
noBackdrop: false,
template: '<p>Pesquisando dados! aguarde ...</p>'
});
var q = $q.defer();
$http.get(ApiAcpEndpoint.url, data)
.then(function(data) {
console.log(' - data.mes '+$scope.mes);
console.log(' - data.origem '+$scope.origem);
var acompanhamento = {};
acompanhamento.dados = [ data ];
$scope.data = acompanhamento.dados;
console.log('pesquisaAcompanhamento data :'+$scope.data);
q.resolve(data);
$ionicLoading.hide();
console.log(' q.promise '+q.promise);
return q.promise;
});
}
})
And in services also however the search result does not return:
.factory('ApiAcp', function($http, $q, ApiAcpEndpoint) {
var getApiData = function(data) {
var q = $q.defer();
$http.get(ApiAcpEndpoint.url,data)
.success(function(data) {
q.resolve(data);
})
.error(function(error){
console.log('Had an error'+error)
q.reject(error);
})
return q.promise;
}
return {
getApiData: getApiData
};
})
This happens because inputs are sent via body in json format.
– Diego Vieira