我正在將google maps v2項目升級到v3。到目前爲止,它已經進展順利,但我遇到了一個問題,我還沒有找到解決方案(儘管我的解決方案有所改進)。Google地圖Ajax調用:v2和v3之間的區別
訪問地圖的用戶可以點擊一個位置,使Lat出現在infoWindow中,並能夠將該數據保存到XML文件中。我在v2中可以正常工作。
它也適用於v3,但只有當我刪除所有的Ajax檢查時,這看起來很危險。 在V2我:
var request = GXmlHttp.create();
// open the request to storeMarker.php on server
request.open('GET', 'storeMarker.php' + getVars, true);
request.onreadystatechange = function() {
if (request.readyState == 4) {
// the request is complete
var xmlDoc = request.responseXML;
// retrieve the root document element (response)
var responseNode = xmlDoc.documentElement;
// retrieve the type attribute of the node
var type = responseNode.getAttribute("type");
// retrieve the content ofthe responseNode
var content = responseNode.firstChild.nodeValue;
//check to see if it was an error, or success
if (type != 'success') {
alert(content);
} else {
// create a new marker and add its info window
var latlng = new GLatLng(parseFloat(lat), parseFloat(lng));
var marker = makeTempMarker(latlng, content, bus);
map.addOverlay(marker);
map.closeInfoWindow();
}
}
不知何故,GXmlHttp.create()似乎與我打電話是「storeMarker.php」,而不是XML在所有文件應對。 storeMarker.php文件打開一個XML文件(併成功保存了新標記)。這段代碼來自'開始使用PHP和Ajax的Google地圖應用程序'(Apress:Purvis,Sambells & Turner,2006),它只適用於v2。
的GXmlHttp.create()不再適用於V3,和我代替打開一個Ajax請求(功能這裏不再重複)短跨瀏覽器的功能:
var request = getAjaxObject();
現在JS上的扼流器'request.responseXML'。我嘗試過'request.responseText',但是(不出所料)也不起作用。
我的問題是,我該怎麼做呢?
正如我上面所說的,如果我刪除'status == 200'檢查之外的響應檢查,並且使用適當的v3語法,標記數據將被保存並且臨時標記將被正確顯示。但它不覺得'安全'。
當你想知道爲什麼V3代碼不起作用時,爲什麼要發佈你的V2代碼? –
[xml解析演示庫](http://gmaps-samples-v3.googlecode.com/svn/trunk/xmlparsing/) – geocodezip
因爲(到目前爲止)我的V3代碼是相同的,除了最初的實例請求。對不起,如果我沒有說清楚。 –