wx.getlocation({
<code> type: 'wgs84', // 默认为wgs84的gps坐标,如果要返回直接给openLocation用的火星坐标,可传入'gcj02'
success: function (res) {
var latitude = res.latitude; // 纬度,浮点数,范围为90 ~ -90
var longitude = res.longitude; // 经度,浮点数,范围为180 ~ -180。
var speed = res.speed; // 速度,以米/每秒计
var accuracy = res.accuracy; // 位置精度
$.ajax({
url:"{:U('home/Share/index')}",
data:{latitude:latitude,longitude:longitude},
type:"POST",
dataType:"json",
success:function(){
}
})
},
})</code>这样用ajax传值在后台controller,var_dump($_POST)是空值,是怎么回事?
wx.getlocation({
<code> type: 'wgs84', // 默认为wgs84的gps坐标,如果要返回直接给openLocation用的火星坐标,可传入'gcj02'
success: function (res) {
var latitude = res.latitude; // 纬度,浮点数,范围为90 ~ -90
var longitude = res.longitude; // 经度,浮点数,范围为180 ~ -180。
var speed = res.speed; // 速度,以米/每秒计
var accuracy = res.accuracy; // 位置精度
$.ajax({
url:"{:U('home/Share/index')}",
data:{latitude:latitude,longitude:longitude},
type:"POST",
dataType:"json",
success:function(){
}
})
},
})</code>这样用ajax传值在后台controller,var_dump($_POST)是空值,是怎么回事?
写法是正确的,至于为什么获取不到就需要自己调试一下你的代码。
立即学习“Java免费学习笔记(深入)”;
肉测办法:
直接输出接受到的数据,然后success中接受返回的对象。
<code>后台输出:
echo json_encode($_POST);exit();
前台输出:
success:function(msg){
console.log(msg);
}</code>ajax是属于异步请求,不能直接在controller输出
微信是一款手机通信软件,支持通过手机网络发送语音短信、视频、图片和文字。微信可以单聊及群聊,还能根据地理位置找到附近的人,带给大家全新的移动沟通体验,有需要的小伙伴快来保存下载体验吧!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号