关于wx.request
小程序这块,官方给出的是GET的用法,所以再做POST需求的时候会有坑出现,因为官方没有响应的文档
下面是小程序官方request的代码
wx.request({
url: "test.php", //仅为示例,并非真实的接口地址
data: {
x: "" ,
y: ""
},
header: {
"content-type": "application/json"
},
success: function(res) {
console.log(res.data)
}
})
小程序官网API如下
先看上面的参数
因为默认的method是GET(使用GET的童鞋不用考虑)
假如,你要用POST你的代码就应该这样写
wx.request({
method:"POST",
url: "test.php", //仅为示例,并非真实的接口地址
data: {
x: "" ,
y: ""
},
header: {
"content-type": "application/x-www-form-urlencoded"
},
success: function(res) {
console.log(res.data)
}
})
这里注意第二个红框!因为官方给出的是application/x-www-form-url-encoded,亲测没有用啊,还是传递不过去data,
然后就改成了application/x-www-form-urlencoded,发现可以了!!!
小程序这边为啥没有反馈呢,坑多到爆炸!