我試圖發佈瀏覽器的geoposition
通過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
});
}
但是,當它在file_2的陣列接收爲空,拋出此警報「通知:未定義指數:座標英寸..」
file_2.php
if(isset($_POST['data'])){
$dataString = $_POST['data'];
$Geoposition = json_decode($dataString, true);
$lat = $Geoposition['coords']['latitude'];
$lng = $Geoposition['coords']['longitude'];
}
嘗試做,print_r的file_2.php –
也是我想你應該設置你的dataType在頁面上($ _ POST): 'JSON' http://api.jquery.com/jquery.ajax/ –
喜there .. print_r prints {} ..設置dataType沒有產生變化..謝謝 – Cactux