L
L
Lizard2018-10-04 04:06:11
AJAX
Lizard, 2018-10-04 04:06:11

How to send the value received using a function in js to the server?

There is a code:

navigator.geolocation.getCurrentPosition(
    function(position) {
      alert('Последний раз вас засекали здесь: ' +
        position.coords.latitude + ", " + position.coords.longitude);
  }
    );

I get position.coords.latitude and position.coords.longitude values.
How to write these values ​​to a file on the server?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Lumore, 2018-10-04
@Lumore

navigator.geolocation.getCurrentPosition(
   function(position) {
      $.ajax({
         url: '/api/setPosition',
         data: {lat: position.coords.latitude, lng: position.coords.longitude},
         method: 'post',
         success: function (response) {
            console.log('success');
         },
         error: function (error) {
            console.error(error);
         }
      });
   }
);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question