小程序中ajax返回数据,请问在小程序中如何从请求success中将数据返回给对象data?...
生活随笔
收集整理的這篇文章主要介紹了
小程序中ajax返回数据,请问在小程序中如何从请求success中将数据返回给对象data?...
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
我的代碼如下:
App({
data: {
posts: {}
},
onLaunch(event) {
// console.log('onLaunch');
var that = this;
swan.request({
url: 'http://www.sfatpaper.com/content.json',
success: function (res) {
console.log(res.data);
that.setData({
posts: res.data.posts
});
},
fail: function (err) {
console.log('錯誤碼:' + err.errCode);
console.log('錯誤信息:' + err.errMsg);
}
})
}
});
通過ajax,目前可以順利讀取接口數據,其中posts的數據有兩項
posts:Array(2)
0:Object
1:Object
我想通過that.setData將數據傳給外層的data對象,以便其他頁面調用
但是報錯顯示:
Uncaught (in promise) TypeError: that.setData is not a function
還望指正,問題出在那里呢?謝謝!
總結
以上是生活随笔為你收集整理的小程序中ajax返回数据,请问在小程序中如何从请求success中将数据返回给对象data?...的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: ajax requestbody传值,a
- 下一篇: his系统存储服务器,关于HIS服务器及