Save variable value javascipt in the database

0
function showpos(position){
  lat=position.coords.latitude
  lon=position.coords.longitude
var enderDe = (+lat+',' +lon);

How do I save the enderDe variable in my database?!

    
asked by anonymous 20.04.2015 / 03:32

1 answer

0

According to your answers, using jQuery.post , you can try the following:

function showpos(position) {
  lat=position.coords.latitude;
  lon=position.coords.longitude;
  var latlon = JSON.stringify({lat:lat,lon:lon});
  saveLatLon(latlon);
}

function saveLatLon(pos) {
  $.post('url/do/teu/php.php',pos,function(data) {
    console.log(data); // aqui voce trata data como quiser
  }
}

On the php side you will have to do anything like

if (isset($_POST['lat']) && isset($_POST['lon'])) {
    // chamada ao MySQL e tratamento de dados aqui
}

In order not to use jQuery, you need to use the XMLHttpRequest to make an AJAX call to your PHP.

    
20.04.2015 / 11:27