-1
我已經將大部分Google Maps演示從API的v2升級到v3。從XML文檔解析標記而不使用GXmlHttp
我有一個工作Handler.ashx從SQL Server數據,摘錄其中的如下返回的XML文件:
<root>
<marker INSTITUTION_KEY="100433" Latitude="40.735772366619301" Longitude="-73.994402766599904" INSTITUTION="New School, The" STREET="65 5th Avenue, Room M107A" CITY="New York" STATE="New York" ZIP="10011" ZIP4="????" WEBSITE="www.newschool.edu">
<Awards AreaID="12" AWARD="N71131B511" WORLDAREA="Western Europe"/>
<Awards AreaID="12" AWARD="N71131B511" WORLDAREA="Western Europe"/>
</marker>
<marker INSTITUTION_KEY="1022" Latitude="25.760174462957600" Longitude="-80.371959517777100" INSTITUTION="Florida International University" STREET="11220 SW 8TH ST" CITY="MIAMI" STATE="FL" ZIP="33184" ZIP4="0000" WEBSITE="www.fiu.edu">
<Awards AreaID="7" AWARD="F91131B511" WORLDAREA="Latin America"/>
<Awards AreaID="7" AWARD="F91131B511" WORLDAREA="Latin America"/>
</marker>
</root>
我讀過GXmlHttp不再存在和我努力嘗試轉換此代碼段:
var request = GXmlHttp.create();
request.open("GET", urlRequest, true);
request.onreadystatechange = function() {
if (request.readyState == 4) {
var xmlDoc = request.responseXML;
var markers = xmlDoc.documentElement.getElementsByTagName("marker");
for (var i = 0; i < markers.length; i++) {
這是我迄今爲止得到了和我堅持:
// Load the xml file using ajax
$.ajax({
type: "GET",
async: true,
url: urlRequest,
dataType: "xml",
success:
function (xml) {
// Parse the xml file and get data
var xmlDoc = $.parseXML(xml);
var markers = xmlDoc.documentElement.getElementsByTagName("marker");
for (var i = 0; i < markers.length; i++) {
希望瞭解如何使這種轉變小費。我發現了一個錯誤:
Uncaught TypeError: Cannot read property 'documentElement' of null
在試圖創建一個數組稱爲標記從行與標記的節點。