小程序 wx.request请求到数据,需要怎样处理才能渲染出来?

wx.request向后台请求数据,后台echo json_encode($res)返回。这时小程序接收到数据,该如何处理?

【注:$res是一个二维数组】


wx.request请求代码

  getmynh: function (sessionid){

    var that = this;

    wx.request({

      url: 'https://xing.zhumingke.cn/index.php/home/index/getmynh',

      data:{

        unionid: sessionid

      },

      header: {

        'content-type': 'application/json'

      },

      dataType:'json',

      success:function(res){

        console.log(res)

        console.log(res.data)

        console.log(typeof(res.data))

        that.getsomething(res)

      }

    })

  },


后端返回数据代码

public function getmynh(){
   $unionid = I('get.unionid');
   $user = M("nhuser");
   $res1 = $user->where(array('unionid'=>$unionid))->find();
   $phone = $res1['phone'];
   $nhcont = M("nhcont");
   $res2 = $nhcont->where(array('fromphone'=>'13922186065'))->field('nhcont',true)->select();
   if(is_array($res2) && !empty($res2)){
       $aaa = json_encode($res2);
       $yt = gettype($aaa);
       file_put_contents(THINK_PATH.'log/log86.txt',$yt);
       echo json_encode($res2);
   }else{
       echo "0";
   }
}


qq_欠你的幸福_0
浏览 6363回答 3
3回答

慕粉0932367111

把拿回来的数据在data里面定义一个变量接收,然后在需要显示的地方将数据绑定

冰封灬尘世

唔~~ 这个问题呀!   明天再告诉你      下班!!!
打开App,查看更多内容
随时随地看视频慕课网APP