前端 js文件
submitcart: function(){
that = this;
var cart = wx.getStorageSync("cart");//获取数据
var address = wx.getStorageSync("addressarray");//获取数据
var cart = JSON.stringify(cart);//编码数据
var address = JSON.stringify(address);//编码数据
wx.request({
url: "https://",//后台地址
data: {
cart:cart, //要发送的数据
address:address,
},
method: "POST", //post
header: {
"Content-Type": "application/x-www-form-urlencoded" //注意关键点必填
},
success: function (res) {
console.log(res)
wx.showToast({
title: "提交数据成功",
icon: "success",
durantion: 2000
})
}
})
},
后台接受数据 .php文件
public function index()
{
$cart = $_POST["cart"];//接收数据
$address = $_POST["address"];//接收数据
$cart =json_decode($cart,true);//解码数据
$cart1 = $cart[0];//编辑数据
$cart1 = json_encode($cart1["id"]);//编码数据
return $cart1;//发送回小程序