Javascript-how to get the longitude and latitude values through WeChat js and how to receive the values in the background

Source: Internet
Author: User
Wx. getLocation ({code...}). In this way, if ajax is used to transmit the value to the backend controller, var_dump ($ _ POST) is a null value. why? Wx. getLocation ({

Type: 'wgs84 ', // The gps coordinate of wgs84 by default. if you want to return the Mars coordinate directly to openLocation, you can pass 'gcj02' success: function (res) {var latitude = res. latitude; // latitude, floating point number, range: 90 ~ -90 var longpolling = res. longpolling; // longitude, floating point number, range: 180 ~ -180. Var speed = res. speed; // speed, measured in meters/per second var accuracy = res. accuracy; // location accuracy $. ajax ({url: "{: U ('Home/Share/index')}", data: {latitude: latitude, longpolling: longpolling}, type: "POST ", dataType: "json", success: function (){}})},})

In this way, if ajax is used to pass values to the backend controller, var_dump ($ _ POST) is a null value. why?

Reply content:

Wx. getLocation ({

Type: 'wgs84 ', // The gps coordinate of wgs84 by default. if you want to return the Mars coordinate directly to openLocation, you can pass 'gcj02' success: function (res) {var latitude = res. latitude; // latitude, floating point number, range: 90 ~ -90 var longpolling = res. longpolling; // longitude, floating point number, range: 180 ~ -180. Var speed = res. speed; // speed, measured in meters/per second var accuracy = res. accuracy; // location accuracy $. ajax ({url: "{: U ('Home/Share/index')}", data: {latitude: latitude, longpolling: longpolling}, type: "POST ", dataType: "json", success: function (){}})},})

In this way, if ajax is used to pass values to the backend controller, var_dump ($ _ POST) is a null value. why?

The statement is correct. you need to debug your code as to why you cannot get it.

Meat test method:

Directly output the received data, and thensuccess.

Background output: echo json_encode ($ _ POST); exit (); foreground output: success: function (msg) {console. log (msg );}

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

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.