微信小程序开发问题记录

微信小程序开发问题记录

所遇问题及其解决

wx.Request使用POST提交

  • 需要设置 header['content-type'] 为 application/x-www-form-urlencoded ,否则传出的时间将为字符串本身,示例代码:
wx.request({
  url: app.globalData.systemUrlPrefix + '/user/wx/wxAppRegister', //接口地址
  data: {
    name: name,
    password: password,
    userInfo: app.globalData.userInfo
  },
  //header: { 'content-type': 'application/x-www-form-urlencoded' },
  method: 'POST',
  success: function (res) {
    wx.showToast({
      title: '提交成功',
      duration: 2000
    })
  },
  fail: function (res) {
    console.log('cuowu' + ':' + res)
  }
})
  • 如果没有设置header,那么后台接收到的数据就将是name='name',password='password',userInfo='userInfo'

你可能感兴趣的:(微信小程序开发问题记录)