Official
developers/miniprogram/dev/api/wx.request:网络交互
Third Parties
- .net/GO_D_OG/details:交互的坑/易错点
- .com/p/acd:小程序自动化测试
wx.request({url: 'test.php', // 仅为示例,并非真实的接口地址data: {x: '',y: ''},header: {'content-type': 'application/json' // 默认值},success(res) {console.log(res.data)}})
wx.request({url: 'https://localhost:8443/xiaochengxu/addBill.do',data: e.detail.value,method: 'POST',header: {'content-type': 'application/x-www-form-urlencoded'},success:function(res) {console.log('submit success');},fail:function(res){console.log('submit fail');},complete:function(res){console.log('submit complete');}})
onLoad: function (options) {var that = this;var list = that.data.list;var currentPage = that.data.currentPage;wx.showNavigationBarLoading(); //在标题栏中显示加载//调用读取数据库的方法this.getdata();},getdata: function () {//定义函数名称var that = this; // 这个地方非常重要,重置data{}里数据时候setData方法的this应为以及函数的this, 如果在下方的sucess直接写this就变成了wx.request()的this了wx.request({url: 'http://localhost:8080/mallapp/app/searchlist',//请求地址/*data: {//发送给后台的数据name: "bella",age: 20},*/header: {//请求头"Content-Type": "applciation/json"},method: "GET",//get为默认方法/POSTsuccess: function (res) {console.log(res.data);//res.data相当于ajax里面的data,为后台返回的数据that.setData({//如果在sucess直接写this就变成了wx.request()的this了.必须为getdata函数的this,不然无法重置调用函数goods: res.data})},fail: function (err) { },//请求失败complete: function () { }//请求完成后执行的函数})},
