wx.request({
url: 'http://127.0.0.1:8090/inStorkAPI/php/add_order_del_multi_carts.php',
data: {
"cartIds":cartIdarr
},
method:"POST",
header:{
'content-type': 'application/x-www-form-urlencoded'
},
success: (result) => {
console.log(result);
},
fail: (res) => {
console.log(res);
},
complete: (res) => {},
})
在header中添加’content-type’: ‘application/x-www-form-urlencoded’
这点很重要:因为默认get请求的编码格式不适合于微信小程序中request的post请求,如果你用的是ajax,这里不设置倒也不影响,因为我测试过了
参考博文链接:https://www.cnblogs.com/mmzs/p/11606472.html
注意:通过php接口接收到的数据不是一个数组,是一个字符串,如果需要数组格式,就需要转化
$cartIds = $_POST['cartIds'];// 接受post请求的一个数组
// 接收到的$cartIds为字符串,需要转换成数组
$cartIds1 = explode(',', $cartIds);
// 补充 通过以下方法先判断得到的数据类型
$orderGoods = $_POST['payGoodsList'];
$type = gettype($orderGoods);
echo $type;