location:function(){
var that = this;
wx.getLocation({
success: function (res) {
wx.request({
url: 'http://apis.map.qq.com/ws/location/v1/ip?key=MAVBZ-RQXRF-D5YJV-J46RA-VTMFS-LFFF5',
data: {},
header: { 'Content-Type': 'application/json' },
success: function (ops) {
console.log(ops.data)
that.setData({
location: ops.data.result.ad_info.district
})
}
})
location:function(){
var that = this;
wx.getLocation({
success: function (res) {
wx.request({
url: 'http://apis.map.qq.com/ws/location/v1/ip?key=MAVBZ-RQXRF-D5YJV-J46RA-VTMFS-LFFF5',
data: {},
header: { 'Content-Type': 'application/json' },
success: function (ops) {
$.ajax({
type: 'post',
url: url,
data: ops.data,
dataType: 'json',
anysc: false,
success: function (res) {
},
error: function () {
}
});
})
}
})
wx.request,和ajax差不多,不过服务器需要https并且启用tls1.2
https://mp.weixin.qq.com/debug/wxadoc/dev/api/network-request.html
ajax向后台传地址,你把地址当作一个参数即可,需要注意中文乱码问题,encodeURI(),后台用servlet去接收request.getParameter("key");
然后就执行如何处理数据或存数据库的问题了。
看图吧
思路就是写个方法,请求后台给过来的接口,然后问后台要传什么给后台,代码楼上大佬给了,呀呀呀,应该是这样的