1. 程式人生 > >小程式請求

小程式請求

onLoad: function () {
    wx.request({
      url: '介面地址', //僅為示例,並非真實的介面地址
      data: {
        id: '1',
        position: '2',
        class_id: '3'
      },
      method: 'POST',
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 預設值
      },
      success(res) {
        console.log(res.data)
      }
    })
  }
後臺可以以key/value值獲取到傳參   

header: {

         'content-type': 'application/x-www-form-urlencoded' 

},
這樣寫獲取不到

header: {

         'content-type': 'application/json' // 預設值

},