
作用:向服务器传数据
wx.request({url: 'test.php', //仅为示例,并非真实的接口地址data: {x: '',y: ''},header: {'content-type': 'application/json' // 默认值},success (res) {console.log(res.data)}})
wx.request({url: app.globalData.pubSiteUrl + 'user-information/get-information', //urlmethod: 'GET', //请求方式header: {'Content-Type': 'application/json',},data: {activityId: options.id, //参数},success: function(res) {if (res.data.code == 1) {_this.setData({phone: res.data.user.phone,password: res.data.user.password})}},fail: function() {app.consoleLog("请求数据失败");},complete: function() {// complete}})
在小程序中,POST请求的Content-Type必须设置为:application/x-www-form-urlencoded
var _this = this;wx.request({url: app.globalData.pubSiteUrl + 'statistics/detail-activity', //上线的话必须是https,没有appId的本地请求貌似不受影响method: 'POST', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECTheader: {'Content-Type': "application/x-www-form-urlencoded",'Cookie': 'SESSION=' + wx.getStorageSync("sessionId")}, // 设置请求的 headerdata: {activityId: options.id,},success: function(res) {app.consoleLog("请求数据成功");_this.setData({ // 设置页面列表的内容activityDetail: res.data.activity});_this.getActivityDetials();},fail: function() {app.consoleLog("请求数据失败");},complete: function() {// complete}})