加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

php – 将JSON发布到Laravel

发布时间:2020-12-14 19:34:01 所属栏目:大数据 来源:网络整理
导读:我正在尝试向Jaravel发送json的帖子请求.请求在服务器上收到,但是当我尝试访问属性时,我得到: “试图获得非对象的属性”. 在客户端我正在使用 angularjs. 角度: $http.post($rootScope.globals.basePath+"login/handleAjax",{"id" : obj.values[0].id,"pro
我正在尝试向Jaravel发送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是有效的,并且它到达控制器方法(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的对象.

$data = Input::all();
$data['id']; // The ID of the request

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读