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
Post a Comment