本节知识点
(一) 小程序get请求
<button class="answer" bindtap="douban">测试豆瓣</button>
douban: function () {
var _this = this;
wx.request({
url: 'xxxxxxx', /*写地址*/
header: {
'content-type': 'json' // 默认值
},
success: function (res) {
console.log(res);
var imgsrc=res.data.image;
_this.setData({
imgsrc1:imgsrc
})
}
})
},
(二)小程序POST请求
<button class="answer" bindtap="fashe">发送数据</button>
fashe: function () {
var _this = this;
wx.request({
url: 'http://localhost:3000/post',
header: { "content-type": "application/x-www-form-urlencoded" },
method:"POST",
data: {
name: "新开始",
sex: "密码"
},
success: function (res) {
console.log(res.data);
var result = res.data.name;
console.log(result);
wx.showModal({
title: '这是收到的数据',
content: JSON.stringify(res),
success: function (res) {
if (res.confirm) {
console.log('用户点击确定');
_this.setData({
jiekou:result
})
} else if (res.cancel) {
console.log('用户点击取消')
}
}
})
}
})
},