我正在尝试通过jQuery Ajax发布浏览器的geoposition
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
});
}
但是当它在file_2中收到时,数组为空并抛出此警告“注意:未定义的索引: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'];
}
答案 0 :(得分:0)
根据日志, stringData 的值为 {} 。它空了