我试图向laravel发送json的发布请求。该请求在服务器上收到,但是当我尝试访问属性时,我得到: “试图获取非对象的属性” 。在客户端上,我正在使用angularjs。
角度:
$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".** }
注意:我可以在Fiddler中看到正在发送的JSON是有效的,并且到达了controller + method(http 200)。
帖子请求本身(如Fiddler所示)
Headers: Accept: application/json, text/plain, */* ... Text View: {"id":"my id","profileUrl":"http://www.linkedin.com/pub/yoel-blum/51/373/76"}
Laravel的Input::all方法返回一个关联数组,而不是PHP的stdClass的对象。
Input::all
$data = Input::all(); $data['id']; // The ID of the request