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'), }, onLoad: function (e) { console.log('首页开始加载。。。') var that = this console.log(app.globalData) console.log('全局变量'); if (1) { console.log('进入') 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("新测试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) { 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 回调输出错误信息看下