與外站(zhàn)進行數據傳輸
<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);
}
})
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
前後端交互
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"> //遍曆一個(gè)數組
<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
});
},
})
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36