原創聲明:本文為作者原創,未經允許不得轉載,經授權轉載需注明作者和出處
最近在學習小程序與后端服務器(mysql)通訊,可是用下面的方法只能是被動顯示。能不能給個立即顯示的代碼?謝謝。
<!--index.wxml-->
<view class="container">
<view bindtap="bindViewRead" >讀取數據</view>
<text>{{text}}</text>
</view>
//index.js
//讀取數據
bindViewRead: function() {
var page = this;
wx.request({
url: ‘https://localhost/mysql/read.php‘,
data: {
key: “asdf33rr”
},
header: {
‘content-type’: ‘application/json’
},
success: function(res) {
page.setData({text:res.data});
console.log(res.data)
}
})
},
用上面的方法只能點“讀取數據”才有顯示,讓他無刷新顯示怎么做?