发布JSON要Laravel [英] Posting JSON To Laravel
问题描述
我试图使JSON的POST请求Laravel。收到请求然而,当我尝试访问的属性我得到的服务器上:
试图让非对象的属性即可。
在客户端我使用angularjs。
角:
$ http.post($ rootScope.globals.basePath +登录/ handleAjax,{ID:obj.values [0] .IDprofileUrl:obj.values [0] .publicProfileUrl})。成功(功能(数据){
的console.log(成功了!,数据);
});
laravel:
类的LoginController扩展BaseController {
在/ *用户日志,LinkedIn,并通过AJAX送他的ID给这个函数* /
公共职能handle_ajax(){
$数据=输入::所有();
* //发条只是我使用调试扩展名是*
发条::信息($数据 - 和SEQ ID); ** //试图让非对象的财产。**
}
注:我可以小提琴手看到正在发送的JSON是有效,以及是否达到控制器+方法(HTTP 200)
POST请求本身(与小提琴手看到)
标题:
接受:应用/ JSON,纯文本/ * / *
...
文本视图:
{ID:我的ID,profileUrl:http://www.linkedin.com/pub/yoel-blum/51/373/76}
Laravel的输入::所有
方法返回一个关联数组,而不是PHP的一个stdClass的对象。
$ =数据输入::所有();
$数据['身份证']; //请求的ID
I am trying to make a post request of json to Laravel. The request is received on the server however when I try to access a property I get: "Trying to get property of non-object". On the client I'm using angularjs.
angular:
$http.post($rootScope.globals.basePath+"login/handleAjax",{"id" : obj.values[0].id,"profileUrl" : obj.values[0].publicProfileUrl}).success(function(data){
console.log("got success!",data);
});
laravel:
class LoginController extends BaseController {
/*User logs in to linkedin and sends his id through ajax to this function*/
public function handle_ajax() {
$data = Input::all();
*//Clockwork is just a debugging extension I'm using*
Clockwork::info($data->id); **//"Trying to get property of non-object".**
}
Note: I can see in Fiddler that the JSON being sent is valid and that it reaches the controller+method (http 200).
The post request itself (As seen with Fiddler)
Headers:
Accept: application/json, text/plain, */*
...
Text View:
{"id":"my id","profileUrl":"http://www.linkedin.com/pub/yoel-blum/51/373/76"}
Laravel's Input::all
method returns an associative array, not an object of PHP's stdClass.
$data = Input::all();
$data['id']; // The ID of the request
这篇关于发布JSON要Laravel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!