Save variable value javascript in database

Asked

Viewed 1,761 times

0

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

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

  • What is the language used on the server?

  • If the language used is PHP, use ajax

  • php,... but wanted to save without the user having to press a button,.. otherwise by post it wouldn’t work

  • 1

    Ajax has nothing to do with user action clicking friend button.

  • sorry dude, but if I’m asking here, it’s already assumed that I don’t understand about,...

  • You use jQuery? If yes, you can make a very easy resolution. If not, you can adapt to Vanilla.

  • I do not use, until then only php and html, now arrived at the moment I need to learn,..

Show 2 more comments

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’ll have to do anything like

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

To not use jQuery, you need to use the Xmlhttprequest to make an AJAX call to your PHP.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.