thinkphp5.0 使用$request->param('xxx')获取ajax传入josn数据data

发送t内容
{"a":{ "x":"123" , "v":"456" },"b":{ "x":"123" , "v":"456" }}

$.ajax({
    type: "POST",
    url: "/api_data/",
    data: {
        Id: id,
        fields: t,
     },
     success: function(data) {
            if (data.code == 1) {
             alert( "success")
           }else(data.code) {
                  alert("error")
            }
          }
 
      },
      error: function(result) {
             alert("error")
        }            

thinkphp5 接收

public function api_data(Request $request)
{
$param = array(); //声明空对象
$param = json_decode($request->param('id'));// 解析数据
$aa = $param->a->x;
$bb = $param->b->v;
}

 

 

posted on 2018-01-25 11:36  逗霸小皓  阅读(756)  评论(0)    收藏  举报

导航