JavaScript-WeChat JS get latitude and longitude how to send value and how to receive the background

Source: Internet
Author: User
Wx.getlocation ({

    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(){                            }        })    },})

So with the Ajax value in the background controller,var_dump ($_post) is a null value, what is going on?

Reply content:

Wx.getlocation ({

    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(){                            }        })    },})

So with the Ajax value in the background controller,var_dump ($_post) is a null value, what is going on?

The wording is correct, as to why you need to debug your code if you don't get it.

Meat testing Methods:

The direct output receives the data, and then the success returned object is accepted.

后台输出:echo json_encode($_POST);exit();前台输出:success:function(msg){        console.log(msg);           }

Ajax is an asynchronous request and cannot be output directly from the controller

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.