小程序不支持wx.request同步请求解决方法
2017-10-21 10:00
417 查看
小程序为了用户体验,所有的request均为异步请求,不会阻塞程序运行
百牛信息技术bainiu.ltd整理发布于博客园
所以当你需要同步请求,锁死操作时,最好将所有的逻辑写在success:function(){}
里面,
不然后出现返回值为空的尴尬
错误代码示例:
更改后的代码为:
百牛信息技术bainiu.ltd整理发布于博客园
所以当你需要同步请求,锁死操作时,最好将所有的逻辑写在success:function(){}
里面,
不然后出现返回值为空的尴尬
错误代码示例:
更改后的代码为:
onShow:function(){
// 页面显示
var commonFunction = require('../../pages/index/common'),
that = this;
var interval = setInterval(function(){
that.setData({
nowTime : commonFunction.formatTime(new Date())
})
},1000);
var request = function(latitude,longitude){
wx.request({
url: that.globalData.API_URL + 'getLocation',
data: {
latitude : latitude,
longitude : longitude
},
method: 'GET',
success: function(res){
let result = res.data.data;
result = JSON.parse(result);
console.log(result);
}
});
};
wx.getLocation({
"type" : 'gcj02',
"success" : function(res){
const latitude = res.latitude;
const longitude = res.longitude;
request(latitude,longitude);
},
"fail" : function(e){
console.log(e);
}
});
},
此文作用仅为填坑,
相关文章推荐
- 微信小程序数据请求方法wx.request
- 小程序发送 request请求失败 提示不在合法域名列表中的解决方法
- 微信小程序之wx.request:fail错误,真机预览请求无效问题解决,安卓,ios网络预览异常
- 微信小程序之wx.request:fail错误,真机预览请求无效问题解决,安卓,ios网络预览异常(转)
- 微信小程序封装请求方法wx.request(OBJECT)
- SQL 2005 Report Server 请求因 HTTP 状态 400 失败: Bad Request 处理方法 的解决方法
- MySql “找不到请求的 .Net Framework 数据提供程序。可能没有安装。”解决方法
- ORA-12514 TNS 监听程序当前无法识别连接描述符中请求服务 的解决方法
- WCF问题:“HTTP 错误 404.17 - Not Found 请求的内容似乎是脚本,因而将无法由静态文件处理程序来处理”解决方法
- wp7使用POST请求Asp.net网页时,HttpWebRequest的BeginGetResponse方法抛出NotSupportException异常的解决方法
- Django POST请求 错误 forbidden(403) CSRF verification failed. Request aborted 解决方法
- 用HttpWebRequest做POST请求时返回Http 417 错误解决方法
- 只进结果集不支持请求的操作的“解决方法”
- [转]IOS程序之HTTP同步请求与异步请求问题解决
- NSMutableURLRequest 发送同步请求get方法
- 有关SQL Server 2008安装时“安全程序支持规则”失败的解决方法
- "无法启动Web服务器。Web服务器无法找到请求的资源" 或 "unable to start debugging on the web server.the web server could not find the request"解决方法
- 虚拟机中ORA-12514 TNS 监听程序当前无法识别连接描述符中请求服务 的解决方法
- 【转】System.Net.HttpWebRequest请求超时的问题解决方法
- win2003 iis 不支持请求(iis iso)的解决方法分析