微信小程序开发入门1——异步请求与数据接收

    1. 在微信小程序的onload()方法内,通过wx.request方法进行请求。类似于jsp中的ajax请求。代码如下:
  • onLoad: function (options) {
    var that = this;
    that.data.courseId = options.courseId;
    console.log( "管理员查看所有打卡");
    wx.request({
    url: app.globalData.myUrl2 + 'minisoftware/helloword/managerGetDaka.do',
    data: {
    "dateStr": "today",
    "courseId": that.data.courseId,
    },
    dataType: 'json',
    header: { 'content-type': 'application/json;charset=ISO-8859-1' },
    method: 'post',
    success(e) {
    console.log(e)
    }
    })
            

      2.在java控制层,编写对应方法。

  • @RequestMapping(value = "/managerGetDaka", method = RequestMethod.POST,produces = "text/plain;charset=UTF-8")
    public @ResponseBody String managerGetDaka(@RequestBody GetDakaParam param,HttpServletRequest request){
    JSONObject jo = new JSONObject();
    jo.put("videoUrl", "test");
    return jo.toString;
    }
    

猜你喜欢

转载自blog.csdn.net/xishuchen0520/article/details/79656557
今日推荐