Getting Javascript variable value in PHP Variable using Ajax -


i want store latitude , longitude values in php variables, unable so. here code. can me out here why these values not getting stored in php variables:

code:

<!doctype html> <html> <body onload="getlocation()"> <p id="demo"></p> <script> var x = document.getelementbyid("demo");  function getlocation() {     if (navigator.geolocation) {         navigator.geolocation.getcurrentposition(showposition);     } else {         x.innerhtml = "geolocation not supported browser.";     } }  function showposition(position) {     x.innerhtml = "latitude: " + position.coords.latitude +     "<br>longitude: " + position.coords.longitude;         var lat = position.coords.latitude;         var longt = position.coords.longitude;         $.ajax({       type: 'post',       data: { latitude : lat, longitude : longt },    });  }         </script> <?php         $var = isset($_post['latitude']);         $var1 = isset($_post['longitude']);         echo $var;         echo $var1; ?> </body> </html> 

assuming lat , longt getting set in javascript (you console.log check make sure), looks setting $var , $var1 variable result of isset() function returns either true or false, rather value of $_post['latitude'] or $_post['longitude']. i'm assuming might have meant:

if (isset($_post["latitude"])) {   $var = $_post['latitude']; }  if (isset($_post["longitude"])) {   $var1 = $_post['longitude']; } 

hope helps.


Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -