與外站進行數(shù)據(jù)傳輸
<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"> //遍歷一個數(shù)組
<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
});
},
})