hand
_1_15_6
4
返回栏目
0k
0k
0.1k
0.1k
1k
0.2k
0.7k
1k
0k
0.2k
0.2k
0.2k
0.1k
1k
0.1k
0.1k
0k
0k
0.5k
0.1k
0.1k
0.3k
0k
0.2k
0.3k
0.5k
1k
0.6k
0.4k
0.4k
0k
0k
0.6k
0.2k
0.1k
1k
7k
0.9k
0k
0.5k
0.4k
0.5k
0.1k
0.1k
0.9k
0k
0.1k
返回微信小程序栏目
作者:
贺及楼
成为作者
更新日期:2022-02-05 22:41:01
作用:向服务器传数据
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', //url
method: '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, CONNECT
header: {
'Content-Type': "application/x-www-form-urlencoded",
'Cookie': 'SESSION=' + wx.getStorageSync("sessionId")
}, // 设置请求的 header
data: {
activityId: options.id,
},
success: function(res) {
app.consoleLog("请求数据成功");
_this.setData({ // 设置页面列表的内容
activityDetail: res.data.activity
});
_this.getActivityDetials();
},
fail: function() {
app.consoleLog("请求数据失败");
},
complete: function() {
// complete
}
})
微信小程序
整章节共47节
快分享给你的小伙伴吧 ~