小程序提交数据到后台做加法运算

源代码:

// pages/add/add.js
let a=0;
let b=0;

Page({
  data:{
    result:""
  },
  //获取a
  GetA(e){
    a=e.detail.value
  },

  //获取b
  GetB(e){
    b = e.detail.value
  },

  //提交并做计算
  add(){
    console.log(a,b)
    let that=this
    wx.request({
      url: 'http://localhost:8080/demo4',
      method:'post',
      header: {
        "Content-Type": "application/x-www-form-urlencoded"
      },
      data:{
        a:a,
        b:b
      },
      success(res){
        console.log("计算成功",res)
        that.setData({
          result:res.data
        })
      },fail(res){
        console.log("计算失败",res)
      }
    })
  }
})

猜你喜欢

转载自blog.csdn.net/weixin_43891901/article/details/104508627