微信小程序与服务器的通讯

37次阅读
没有评论

直接加载服务器数据

wx.request({
        url: "https://************/fenlei.php",
        data: {
          a: ""  //参数
        },
        header: {
          "Content-Type": "applicatiSon/x-www-form-urlencoded"
        },
        method: "POST",
        success: function (res) {
          // console.log(res.data)
          console.log(res.data)
          that.setData({
            listfl: res.data,
            //res代表success函数的事件对,data是固定的,list是数组
          })
        }
      })
  }

带密钥提交并且接收返回值

          //e.currentTarget.dataset.name); //提交数据的值
            wx.request({
            url: 'https://*********/test.php',
            data: {
              fenlei: e.currentTarget.dataset.name,
              passWord: '123',
            },
            method: 'GET',
            header: {
              'content-type': 'application/json'
            },
            success: function (res) {
              console.log(res.data)
              wx.showModal({
                title: '提示',
                content: res.data,//返回值

              })
            },
            fail: function (res) {
              wx.showModal({
                title: '提示',
                content: res.data,
              })
            }
          })

带密钥提交并且接收返回值,刷新到页面

bindItemTap: function (e) {
    var that = this
         if (!e.cancel) {
            //可否执行查询操作
          wx.request({
            url: 'https://*****/test.php',
            data: {
              fenlei: e.currentTarget.dataset.name,
              passWord: '12345',
            },
            method: 'GET',
            header: {
              'content-type': 'application/json'
            },
            success: function (res) {
              console.log(res.data)
              that.setData({
                list: res.data,
                //res代表success函数的事件对,data是固定的,list是数组
              })
            }
          })
      }
正文完