• 微信小程序发送ajax


    微信小程序通过 wx.request发送ajax请求

    1. GET

       wx.request({
          url: app.globalData.pubSiteUrl + 'user-information/get-information', //url
          method: 'GET', //请求方式
          header: { 
            'Content-Type': 'application/json',
          },
           data: {
            activityId: options.id,  //参数
          },
          success: function(res) {
            if (res.data.code == 1) {
              _this.setData({
                phone: res.data.user.phone,
                password: res.data.user.password
              })
            }
          },
          fail: function() {
            app.consoleLog("请求数据失败");
          },
          complete: function() {
            // complete 
          }
        })

    2. POST

    在小程序中,POST请求的Content-Type必须设置为:application/x-www-form-urlencoded

    var _this = this;
    wx.request({
      url: app.globalData.pubSiteUrl + 'statistics/detail-activity', //上线的话必须是https,没有appId的本地请求貌似不受影响 
      method: 'POST', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT 
      header: {
        'Content-Type': "application/x-www-form-urlencoded",
        'Cookie': 'SESSION=' + wx.getStorageSync("sessionId")
      }, // 设置请求的 header
      data: {
        activityId: options.id,
      },
      success: function(res) {
        app.consoleLog("请求数据成功");
        _this.setData({ // 设置页面列表的内容
          activityDetail: res.data.activity
        });
        _this.getActivityDetials();
      },
      fail: function() {
        app.consoleLog("请求数据失败");
      },
      complete: function() {
        // complete 
      }
    })
  • 相关阅读:
    使用积分图像统计元素
    compareHist
    均值平移算法
    课后作业-阅读任务-阅读提问-1
    《对软件工程课程的期望》
    自我介绍
    作业
    结对-结对编项目作业名称-需求分析
    对软件工程课程的期望
    自我介绍
  • 原文地址:https://www.cnblogs.com/xiaolinstudy/p/9510299.html
Copyright © 2020-2023  润新知