- 在公众号html5项目中发现的ajax的问题?
我的是微信公众号html项目。function LoadProductType() { var jwtToken = getJwtTokenCookie(); if (jwtToken != '' && jwtToken != 'undefined' && jwtToken != null) { $.ajax({ async: false, url: '/ShoppingCity/GetProductType?r=' + Math.random(), type: 'GET', headers: { 'Authorization': 'Bearer ' + jwtToken }, success: function (response) { productType = response.data.allTypeList; hotkey = response.data.hotKeyList; firsttype = response.data.firstType; }, error: function (xhr, status, error) { console.error('请求失败:', status, error); } }); } },这里的jwtToken实际是localStorage.getItem('jwtToken')取值,一直都有值,但是这个ajax隔几个小时后,'Bearer ' + jwtToken就是空的了,刚开始是可以正常赋值的(比如我退出微信重新进入,或者第一次打开该公众号),不能赋值。
03-28 - 项目公众号网页,代码在微信开发者工具中正常,在真机中有问题,问题出在headers,求解?谢谢!
项目是公众号网页,使用的是jwt,这个代码在微信开发者工具中是正常的,但在真机中有问题,问题出在headers,请求没有发起,后台接口日志中看不到有请求过来。困在这里很久了,是手机微信浏览器的安全设置问题?手机微信的版本是最新的。 $.ajax({ async: true, url: '/ShoppingCity/GetProductType?t=' + new Date().getTime(), type: 'GET', headers: { 'Authorization': 'Bearer ' + jwtToken, 'Content-Type': 'application/json' }, success: function (response) { alert('LoadProductType ===>response<===' + response.data.a); // 请求成功时的回调函数 mark = response.data.a; }, error: function (xhr, status, error) { console.error('请求失败:', status, error); alert('请求失败,请检查网络或联系管理员。' + status + '<===>' + error); } });
03-18