What im trying to do here is sending a JavaScript variable to a PHP function. What I'm developing is a jQuery Mobile App where you can check in when you reach a specific longitude/latitude. But I'm having problem with sending the longitude/latitude to the PHP-function. Im sending it to a PHP-function because im gonna do a comparison with the longitude/latitude that I've stored in my database.
Here's my code.
function testResults() {
if(navigator.geolocation) {
//Get the current position
navigator.geolocation.getCurrentPosition(function(position) {
var latitude = position.coords.latitude;
var longitude = position.coords.longitude;
document.write("lat", latitude);
document.write('<br /><br />');
document.write("long", longitude);
});
} else {
alert("Sorry... your browser does not support the HTML5 GeoLocation API");
}
//////////// Here I tried with jQuery/Ajax. I know that it's wrong.
//////////// Im putting it here so that it maybe clarifies what Im
//////////// trying to do.
$.post("checkLocation.php", {
lat : latitude,
longi : longitude
}, function(data) {
alert("Data Loaded: " + data);
});
////////////////////////////////////////////////////////////////////
}
testResults();
How do I approach this problem? I've tried with JSON, but i didn't get it to work. Any help will be appreciated.