小程序官方请求封装

POST

function _post(url, data, success, fail) {
  wx.request({
    url: http +url,
    header: {
      'content-type': 'application/x-www-form-urlencoded',
    },
    method: 'POST',
    data: data,
    success: function (res) {
      success(res);
    },
    fail: function (res) {
      fail(res);
    }
  });
}

请求写法

http._post('XX/XX/XX',{DATA},function(res){},function(res){})

GET

function _get(url, success, fail) {
  wx.request({
    url: myHttps+url,
    header: {
      'Content-Type': 'application/json'
    },
    success: function (res) {
      success(res);
    },
    fail: function (res) {
      fail(res);
    }
  });
}

请求写法

http._get('XX/X/XX?id=id',function(res){},function(res){})

  

posted @ 2017-11-15 16:27  好想再胖十斤  阅读(248)  评论(0编辑  收藏  举报