小程序提交數據到後臺做加法運算

源代碼:

// 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)
      }
    })
  }
})
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章