收藏
回答

wx.request为什么无法起作用?

如下代码在开发工具真机测试时,日志只能打印到console.log("app.globalData.wxcode---------------" + app.globalData.wxcode);
后面wx.request没有任何反馈,服务器端也无任何调用记录。
但是在开发工具一开始加载本项目时,是正常可以获取服务端数据的,百思不得其解,请大佬们解惑,困扰一天了。



Page({
  data: {
    canIUse: wx.canIUse('button.open-type.getUserInfo'),
  },
  onLoadfunction (e{   //加载入口
    console.log('首页开始加载。。。')
    //custId -----: ' + custId)
    var that = this
    console.log(app.globalData)
    console.log('全局变量');
    // if (!app.globalData.userInfo) {
    if (1) {
      console.log('进入')
      var that = this;
      wx.getSetting({
        success (res){
          if (res.authSetting['scope.userInfo']) {
            wx.getUserInfo({
              successfunction(res{
                console.log(res.userInfo)
                that.setData({
                  userInfo: res.userInfo
                })
                app.globalData.userInfo=res.userInfo;
                console.log("新测试0" + app.globalData.wxcode);
                console.log("新测试1" + res.userInfo.avatarUrl);
                console.log("新测试2" + app.globalData.userInfo.avatarUrl);
         
                   let obj = {};
                   console.log(app.globalData.userInfo);
                   //头像
                   obj.avatarUrl = app.globalData.userInfo.avatarUrl;
                   //性别
                   obj.gender = app.globalData.userInfo.gender;
                   //昵称
                   obj.nickName = app.globalData.userInfo.nickName;
                   //国家
                   obj.country = app.globalData.userInfo.country;
                   //省份
                   obj.province = app.globalData.userInfo.province;
                   //城市
                   obj.city = app.globalData.userInfo.city;
                   console.log(obj);
                   console.log("app.globalData.wxcode---------------" + app.globalData.wxcode);
           
                   wx.request({
                     url: properties.getURL() + '/test/getOpenId.do',
     
                     data: {
                       wxcode: app.globalData.wxcode,
                       nickName: app.globalData.userInfo.nickName,
                       city: app.globalData.userInfo.city,
                       avatarUrl: app.globalData.userInfo.avatarUrl,
                       gender: app.globalData.userInfo.gender,
                       fatherCustId:e.custId,
                       fatherName:e.custNickname
                     },
                     header: {
                       'content-type''application/json' // 默认值
                     },
                     success(res) {
                       //success: function (res) {
                       console.log("res.responseCode : " + res.data.responseCode)
                       if (res.data.responseCode == 0) {
                         console.log("data  ffffffff  : " + JSON.stringify(res.data.data))
                         app.globalData.custid = res.data.data.user.custid
                         console.log(" app.globalData.custid  ffffffff  : " + JSON.stringify(app.globalData.custid))
                       }
                     }
           
           
                   })


              }
            })
          }
        }
      })
  

      //})
      
      } 
   

回答关注问题邀请回答
收藏

3 个回答

  • 跨商通
    跨商通
    02-09

    难道此时不应该去单独测试一下wx.request?以判断是否它的问题?

    02-09
    有用
    回复
  • 💡
    💡
    02-08

    wx.request 加个 fail 回调输出错误信息看下

    02-08
    有用
    回复
  • 常林
    常林
    02-08

    这是真机测试非正常加载的日志

    02-08
    有用
    回复
登录 后发表内容
问题标签