I
I
igorc752018-04-24 10:52:59
PHP
igorc75, 2018-04-24 10:52:59

How to transfer the defined city to a variable?

When visiting the page, the city is determined, but I need to pass this city to $_SESSION['city'], I can't figure out how.

<script src="https://api-maps.yandex.ru/2.0/?load=package.full&lang=ru-RU" type="text/javascript"></script>
<script>
  $(document).ready(function(){
  ymaps.ready(function(){
  var geolocation = ymaps.geolocation;				
  $('#city').text('Город: '+geolocation.city);
  });});
</script>
<div id="city"></div>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
VivaLaGleb, 2018-04-26
@igorc75

$.ajax({
  method: "POST",
  url: "some.php",
  data: { city: geolocation.city }
})

$_SESSION['city'] = $_POST['city']

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question