JSON with PHP Slim and AngularJS

I am trying to send some data from my AngularJS project to a PHP server where I am using PHP Slim, but I tried everything I know and nothing works.

SERVER PHP SLIM

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

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

      

It works if I print 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 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 am getting an empty array [0].

And if I try to use $ resource I got obj, but not as 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 this:

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

      

Can anyone tell me what I am doing wrong?

+3


source to share


1 answer


The second argument to the $http.get

method is not the GET parameters, but the request configuration.

You want to use something like this (note the key params

in the config argument and the absence ?

at the end of the 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: The $ http get options don't work and the config argument docs .

+3


source







All Articles