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 protected]&phone=12313

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

var obj = { name:"Hello",email:"[email protected]"};
$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:"[email protected]"};
            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?

1 Answer 1

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:"[email protected]"};
$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.

Sign up to request clarification or add additional context in comments.

1 Comment

thanks, I worked it. I thought the usage of the name "params" was optional.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.