Official

  1. wx.request({
  2. url: 'https://localhost:8443/xiaochengxu/addBill.do',
  3. data: e.detail.value,
  4. method: 'POST',
  5. header: {'content-type': 'application/x-www-form-urlencoded'},
  6. success:function(res) {
  7. console.log('submit success');
  8. },
  9. fail:function(res){
  10. console.log('submit fail');
  11. },
  12. complete:function(res){
  13. console.log('submit complete');
  14. }
  15. })
  1. onLoad: function (options) {
  2. var that = this;
  3. var list = that.data.list;
  4. var currentPage = that.data.currentPage;
  5. wx.showNavigationBarLoading(); //在标题栏中显示加载
  6. //调用读取数据库的方法
  7. this.getdata();
  8. },
  9. getdata: function () {//定义函数名称
  10. var that = this; // 这个地方非常重要,重置data{}里数据时候setData方法的this应为以及函数的this, 如果在下方的sucess直接写this就变成了wx.request()的this
  11. wx.request({
  12. url: 'http://localhost:8080/mallapp/app/searchlist',//请求地址
  13. /*data: {//发送给后台的数据
  14. name: "bella",
  15. age: 20
  16. },*/
  17. header: {//请求头
  18. "Content-Type": "applciation/json"
  19. },
  20. method: "GET",//get为默认方法/POST
  21. success: function (res) {
  22. console.log(res.data);//res.data相当于ajax里面的data,为后台返回的数据
  23. that.setData({//如果在sucess直接写this就变成了wx.request()的this了.必须为getdata函数的this,不然无法重置调用函数
  24.   goods: res.data
  25.  })
  26. },
  27. fail: function (err) { },//请求失败
  28. complete: function () { }//请求完成后执行的函数
  29. })
  30. },