Valor_ Valor_ - 1 year ago 49
PHP Question

Data isn't passed to api call

I'm working on one project with AngularJs(1.5) and Codeigniter rest server. I'm wondering why data idTag isn't passed to php? Let me show you my code and explain further with comments.

I have this factory

factory.get = function(idLocation, idTag){
console.log(idLocation, idTag); //Console log outputs 1 6, so data is here

return $http({
method: 'GET',
url: $location.protocol() + '://' + $ + '/rest/api/locationtag/locationtag/' + idLocation,
data: {
idTag: idTag
}).then(function successCallback(response){
// response is empty, because data isn't sent to PHP
},function errorCallback(response){
console.log('Error getting slide shows: ' +;

And this is my PHP where i try to fetch the code

public function locationtag_get($idLocation)
$condition['id_location'] = $idLocation;
$condition['id_tag'] = $this->get('idTag');
$locationTag = $this->locations_tags->get($condition);
if ($locationTag) {
$this->response($locationTag, REST_Controller::HTTP_OK);

Out put of var_dump is

'id_location' '1'
'id_tag' null

SO the question, why or how to properly send data from GET method to PHP rest controller in Codeigniter?

If you need any additional information's, please let me know and i will provide. Thank you in advance!

Answer Source

For GET requests you should use params instead of data (which is for POST requests). You can confirm this in the AngularJS documentation.

params – {Object.} – Map of strings or objects which will be serialized with the paramSerializer and appended as GET parameters.

Of course, nothing stops you from adding them to the URL but you'd have to deal with encoding the information properly instead of just passing the JSON object.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download