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

小程序 文章 2021-02-08 22:41 495 0 全屏看文

AI助手支持GPT4.0

wx.request为什么无法起作用?Why can't wx.request work?

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))                       }                     }                                         })              }            })          }        }      })        //})            }    

The following code can only be printed to the console.log (" app.globalData.wxcode ---------------" +  app.globalData.wxcode ); behind wx.request There is no feedback, and there is no call record on the server side. However, when the development tool started to load this project, it was normal to get the server-side data. I couldn't think of the solution. Please solve the puzzle for a day. Page({  data: {    canIUse:  wx.canIUse (' button.open - type.getUserInfo ',}, onload: function (E) {/ / load entry console.log ('home page starts loading... ')    //custId -----: ' + custId)    var that = this     console.log ( app.globalData )     console.log ('global variable '); / / if (! app.globalData.userInfo ) {    if (1) {       console.log ('enter ') var that = this;        wx.getSetting ({        success (res){          if ( res.authSetting [' scope.userInfo ']) {             wx.getUserInfo ({              success: function(res) {                 console.log ( res.userInfo )                 that.setData ({                   userInfo:  res.userInfo                 })                 app.globalData.userInfo=res .userInfo;                 console.log (new test 0 + app.globalData.wxcode );                 console.log (new test 1) + res.userInfo.avatarUrl );                  console.log (new test 2 + app.globalData.userInfo .avatarUrl);                            let obj = {};                    console.log ( app.globalData.userInfo ); / / head portrait obj.avatarUrl  =  app.globalData.userInfo . avatarurl; / / gender obj.gender  =  app.globalData.userInfo .gender; / / nickname obj.nickName  =  app.globalData.userInfo . nickname; / / Country obj.country  =  app.globalData.userInfo .country; / / Province obj.province  =  app.globalData.userInfo . province; / / City 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,                       fat herCustId:e.custId ,                        f atherName:e.custNickname }, header: {content type ':'application / JSON' / / default},                      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 ))                        }                     }                                         })              }            })          }        }      })        //})            }    

回答:

💡:

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

Mr.Zhao:

没配置request合法域名

常林:

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

-EOF-

AI助手支持GPT4.0


国内超级便宜服务器

摸鱼人热门新闻聚合

钻级赞助商 我要加入

开发者在线工具

第三方支付技术请加QQ群

相关文章
我按照平时的方法创建自定义组件,老是报路径错误,不知怎么回事?
使用web-view跳转第三方的的网页,但是后台配置不了这个业务域名,这个问题怎么解决?
关于切换tab跳转不同页面 有什么思路?
个人小商店什么时候支持商品分类?
微信小程序中一键关注公众号接口开放了吗?
随便看看
企业微信通讯录账号被管理员误/恶意删除,怎么办? 8389
问题? 7605
如何快速搭建抽奖助手小程序(无需代码知识) 5179
许涛 大哥在吗, 要解冻小程序的时候提示信息主体不一致, 能帮忙看下吗? 6347
小程序搜一搜全称搜索不显示 麻烦解决一下!谢谢 5755
我的小程序广告收款主体是个体工商户,每个月邮寄两次发票很是麻烦,我年底的时候打包邮寄一次可以么? 5417
如何解决渲染层网络错误Failed to load media? 16671
小程序找号找回 释放昵称? 2606
我的小程序广告主收入5301,实际进账4406,是怎么回事呀? 2580
删除部分微信用户个人数据的通知,怎么删除? 5640