与外站进行数据传输
<view class="bt-ok" bindtap="okClick">确定提交</view>
Page({
okClick: function () {
var that = this;
wx.request({
url: 'http://wq.ycwjwl.com/json.php',
method: 'POST',
data: {
x: 'df so handsome',
y: '2'
},
header: {
'content-type': 'application/x-www-form-urlencoded'
},
success: function (res) {
console.log(res);
var r = res.data.x;
that.setData({
toastHidden: false,
toastTxt: "提交成功",
rt: r
});
}
})
console.log("log:"+this.data.rt);
}
})
前后端交互
Page({
data: {
orderList: [],
total: 0,
},
onLoad: function(options) {
},
returnClick: function () {
wx.navigateBack();
},
})
<view class="cost">总价:<span>¥{{total}}</span></view>
<view class="bt-return" bindtap="returnClick">返回修改</view>
<view class="orderlist" wx:for="{{orderList}}" wx:key="item.id"> //遍历一个数组
<span>{{item.title}}</span><span style="float:right;">¥{{item.cost}} * {{item.num}}</span>
</view>
页面之间传值
Page({
sublimitClick: function (e) {
var agrs = JSON.stringify(this.data.orderList);
wx.navigateTo({
url: '../order/order?order=' + agrs
})
},
})
Page({
onLoad: function (options) {
var order = JSON.parse(options.order);
var t_order = [];
var t_total = 0;
for (var k in order) {
if (order[k].num > 0) {
t_order.push(order[k]);
t_total = t_total + order[k].cost * order[k].num;
}
}
this.setData({
orderList: t_order,
total: t_total
});
},
})