3

I am trying to send some data from my AngularJS Project to a PHP Server where I am using PHP Slim but I have tried everything I know and nothing seems to work.

SERVER PHP SLIM

$app->get('/create',function() use ($app) {

        $data = $app->request()->params();
        response_json(200,"DB: User Created",$data);
});

It works if I type directly from the browser

http://localhost:8888/core/users/create?login=test&password=123&name=Test&email=test@test.com&phone=12313

But if I try to send from the app using $http or $resource

var obj = { name:"Hello",email:"hello@email.com"};
$http.get('/core/users/create?',obj).success(function(data){console.log(data); });

I get an empty Array[0].

And if I try to use $resource I got an obj but not how I expected.

.factory('qServer',function($resource){
return $resource('/core/users/create?:data',{data: '@data'});
});

var obj = { name:"Hello",email:"hello@email.com"};
            var send = JSON.stringify(obj);
            //console.log(lol);
            qServer.get({data:send},function(data) { console.log(data) }); 

With this code I get an Object like that:

data: Object
{"name":"Hello","email":"hello@email_com"}: ""

Anyone could tell me what I am doing wrong?

fracz
  • 20,536
  • 18
  • 103
  • 149
Gabriel Lopes
  • 943
  • 6
  • 11
  • 20

1 Answers1

3

The second argument of $http.get method is not GET params but a request config.

You want to use something like this (notice the params key in config argument and lack of ? at the end of URL):

var obj = { name:"Hello",email:"hello@email.com"};
$http.get('/core/users/create', {params: obj})
.success(function(data){console.log(data); });

See also: Q: $http get parameters does not work and config argument docs.

Community
  • 1
  • 1
fracz
  • 20,536
  • 18
  • 103
  • 149