1 微信小程序POST请求参数传递不到后台
需要在微信请求 wx.request 改变默认 header 配置为如下
wx.request({
url: 'test.php', //仅为示例,并非真实的接口地址
data: {
x: '' ,
y: ''
},
header: {
'content-type': 'application/x-www-form-urlencoded' // 改变默认值为这个配置
},
success: function(res) {
console.log(res.data)
}
})
2 前台获取不到后端返回的数据
需要在微信请求 wx.request 改变默认 dataType 配置为如下
wx.request({
url: 'test.php', //仅为示例,并非真实的接口地址
data: {
x: '' ,
y: ''
},
header: {
'content-type': 'application/x-www-form-urlencoded' // 改变默认值为这个配置
},
dataType: 'json', // 添加这个配置
success: function(res) {
console.log(res.data)
}
})
3 post 请求返回 404 但后台能收到数据
这个需要后台的配置 <