Skip to content Skip to sidebar Skip to footer

Send Lat And Long Details Via Ajax

I am trying to write some code that once the button is pressed it sends the lat and long coordinates via ajax to the test.php file. The problem i am having is that it does not see

Solution 1:

Here. I've set up a fiddle for you. It looks like you may be referencing the wrong method name (getCurrentPosition vs redirectToPosition). If that's not the case, it looks like you never actually call redirectToPosition(), and that's why that code block never executes.

Try editing that fiddle, but changing out your actual domain URI.

    var x = document.getElementById("demo");

  function getLocation() {
     if (navigator.geolocation) {
      navigator.geolocation.getCurrentPosition(showPosition);
  } else { 
      x.innerHTML = "Geolocation is not supported by this browser.";
      }
  }

function getCurrentPosition(position) {

 // ...
  $.ajax({
    type: "POST",
    url: "http://www.domain.co.uk/test.php", // -> Actual domain here.
    data:   "lat="+position.coords.latitude+"&long="+position.coords.longitude

  });
}

http://jsfiddle.net/tcysvkfz/

At any rate, the method that executes your AJAX request is never invoked in your example, and that's why test.php is never hit.


Post a Comment for "Send Lat And Long Details Via Ajax"