这篇文章主要介绍了微信小程序 网络请求(post请求,get请求)的相关资料,需要的朋友可以参考下
微信小程序 网络请求
1.post请求:
onLoad: function() {
that = this;
wx.request( {
url: "url",
header: {
"Content-Type": "application/x-www-form-urlencoded"
},
method: "POST",
data: {},
complete: function( res ) {
console.log(res.data)
});
if( res == null || res.data == null ) {
console.error( '网络请求失败' );
return;
}
}
})
},2.GET请求
onLoad: function () {
console.log('onLoad')
var that = this
wx.request({
url: 'http://json.bmbstack.com/cinemaList',
data: {},
method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
header: {
'Accept': 'application/json'
}, // 设置请求的 header
success: function(res){
that.data.items= res.data
},
fail: function() {
// fail
},
complete: function() {
// complete
}
})
}感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
更多微信小程序 网络请求(post请求,get请求)相关文章请关注PHP中文网!
微信是一款手机通信软件,支持通过手机网络发送语音短信、视频、图片和文字。微信可以单聊及群聊,还能根据地理位置找到附近的人,带给大家全新的移动沟通体验,有需要的小伙伴快来保存下载体验吧!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号