微信小程序wx.request

wx.request({
    
    
  url: 'test.php', //仅为示例,并非真实的接口地址
  data: {
    
    
    x: '',
    y: ''
  },
  header: {
    
    
    'content-type': 'application/json' // 默认值
  },
  success (res) {
    
    
    console.log(res.data)
  }
  fail: function (res) {
    
    
     console.log('Fail to request !')
     console.log(res)
  }
})

1.url :服务器的url地址
2.header(请求header)
content-type 默认为 application/json
对于 header[‘content-type’] 为 ‘application/json’ 的数据,会对数据进行 JSON 序列化
对于 header[‘content-type’] 为 ‘application/x-www-form-urlencoded’ 的数据,会将数据转换成 query string

猜你喜欢

转载自blog.csdn.net/qq_43811879/article/details/112068699