I'm trying to post browser's geoposition
via jQuery Ajax
if (window.navigator.geolocation) {
var failure, success;
success = function(position) {
var stringData = JSON.stringify(position, null);
$.ajax({
type: 'POST',
url: 'file_2.php',
data: { data: stringData }
});
};
failure = function(message) {
alert('Cannot retrieve location!');
};
navigator.geolocation.getCurrentPosition(success, failure, {
maximumAge: Infinity,
timeout: 5000
});
}
But when its received in file_2 the array is empty and throw this alert "Notice: Undefined index: coords in..."
file_2.php
if(isset($_POST['data'])){
$dataString = $_POST['data'];
$Geoposition = json_decode($dataString, true);
$lat = $Geoposition['coords']['latitude'];
$lng = $Geoposition['coords']['longitude'];
}
Based on the log, stringData's value is {}. Its empty