我正试图从我的AngularJS项目发送一些数据到PHP服务器,我使用PHP Slim,但我已经尝试了我所知道的一切,似乎没有任何工作。
SERVER PHP SLIM
$app->get('/create',function() use ($app) {
$data = $app->request()->params();
response_json(200,"DB: User Created",$data);
});
如果我直接在浏览器中输入
http://localhost:8888/core/users/create?login=test&password=123&name=Test&email=test@test.com&phone=12313
但是如果我尝试使用$http或$resource
从应用程序发送var obj = { name:"Hello",email:"hello@email.com"};
$http.get('/core/users/create?',obj).success(function(data){console.log(data); });
我得到一个空数组[0]。
如果我尝试使用$resource,我得到了一个对象,但不是我期望的。
.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) });
通过下面的代码,我得到了一个对象:
data: Object
{"name":"Hello","email":"hello@email_com"}: ""
谁能告诉我我做错了什么? $http.get
方法的第二个参数不是GET参数,而是请求配置。
你想使用这样的东西(注意配置参数中的params
键和URL末尾缺少?
):
var obj = { name:"Hello",email:"hello@email.com"};
$http.get('/core/users/create', {params: obj})
.success(function(data){console.log(data); });