小程序P34 数据请求-GET和POSE的请求
<!--pages/home/home.wxml-->
<button bindtap="getInfo">发起GET请求</button>
<button bindtap="postInfo">发起POST请求</button>
// pages/home/home.js
Page({
//发起Get请求
getInfo(){
wx.request({
url: 'https://www.escook.cn/api/get',
method:"GET",
data:{
name:'ZS',
age:20
},
success:(res)=>{
console.log(res.data)
}
})
},
//发起POSE请求
postInfo(){
wx.request({
url: 'https://www.escook.cn/api/post',
method:"POST",
data:{
name:'ls',
age:33
},
success:(res)=>{
console.log(res.data)
}
})
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
this.getInfo()
this.postInfo()
},
})
- 复制链接
- 举报