-6
我在谷歌地圖api頁面發現了一個腳本,用戶可以在其中選擇位置並將數據發送到PHP - > MySQL。它在Chrome和IE中工作正常,但是當我嘗試在mozilla中保存位置時,它所做的只是刷新父頁面。 我幾乎無言以對,當涉及到的JavaScript,因此,如果任何人都可以找到錯誤,將不勝感激:)Google maps api javascript在mozilla中不起作用
代碼
<!DOCTYPE html >
<head>
<meta name=viewport content='initial-scale=1.0, user-scalable=no' />
<meta http-equiv='content-type' content='text/html; charset=UTF-8'/>
<title>Google Maps JavaScript API v3 Example: Map Simple</title>
<script type='text/javascript' src='https://maps.googleapis.com/maps/api/js'></script>
<script type='text/javascript'>
var marker;
var infowindow;
function initialize() {
var latlng = new google.maps.LatLng(33.137550, -42.187500);
var options = {
zoom: 1,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(document.getElementById('map-canvas'), options);
var html = "<table><tr><td><input type='button' value='Save Location' onclick='saveData(), window.parent.location.reload();'/></td></tr></table>";
infowindow = new google.maps.InfoWindow({
content: html
});
function addMarker(location) {
if (!marker) {
marker = new google.maps.Marker({
position: location,
map: map
});
}
else { marker.setPosition(location); }
}
google.maps.event.addListener(map, 'click', function(event) {
addMarker(event.latLng);
google.maps.event.addListener(marker, 'click', function() {
infowindow.open(map, marker);
});
});
}
function saveData() {
var latlng = marker.getPosition();
var url = 'insert_location.php?lat=' + latlng.lat() + '&lng=' + latlng.lng();
downloadUrl(url, function(data, responseCode) {
if (responseCode == 200 && data.length >= 1) {
infowindow.close();
}
});
}
function downloadUrl(url, callback) {
var request = window.ActiveXObject ?
new ActiveXObject('Microsoft.XMLHTTP') :
new XMLHttpRequest;
request.onreadystatechange = function() {
if (request.readyState == 4) {
request.onreadystatechange = doNothing;
callback(request.responseText, request.status);
}
};
request.open('GET', url, true);
request.send(null);
}
function doNothing() {}
</script>
</head>
<body style='margin:0px; padding:0px;' onload='initialize()'>
<div id='map-canvas' style='width: 100%; height: 800px'></div>
<div id='message'></div>
</body>
</html>
什麼是'window.parent.location.reload'在那裏做? – lucas 2015-02-06 14:18:12
謝謝@lucas。 – krneki 2015-02-06 15:56:22