2013-01-04 49 views
0

我試圖把我的XML標記結果,並將其加載到地圖,但後結果我在我的變量是說我警惕的是:不能得到所有崗位上取得成功的XML數據

數據加載:對象的XMLDocument]

這是我的代碼是什麼樣子:

function SendData() { 

//get data from inputs 

      $.ajax({ 
       type: "POST", 
       url: "MapSearchxml.php", 
       data: { 
        dataFromDate: FromDate, 
        //some more data 
        dataHasPatio: HasPatio 
       }, 
       beforeSend: function (html) { // this happens before actual call 
       }, 
       success: function (html) { // this happens after we get results 

       alert("Data Loaded: " + html); 

       } 
      }); 
} 

在Firebug中,後的反應是這樣的:

<markers><marker id="1" lat="48.153938" lng="17.108459" /></markers>

我嘗試設置數據類型,以這樣的XML:

   success: function (html) { // this happens after we get results 
       alert("Data Loaded: " + html); 
       }, 
       dataType: 'xml' 
      }); 
} 

然而沒有變化發生。

這裏是我的XML的PHP​​代碼:

$result = mysql_query($query); 
if (!$result) { 
    die('Invalid query: ' . mysql_error()); 
} 


header("Content-type: text/xml"); 

echo '<markers>'; 

while ($row = @mysql_fetch_assoc($result)){ 
    echo '<marker '; 
    echo 'id="' . parseToXML($row['ID']) . '" '; 
    echo 'lat="' . parseToXML($row['LAT']) . '" '; 
    echo 'lng="' . parseToXML($row['LNG']) . '" '; 
    echo '/>'; 
} 

echo '</markers>'; 
+0

你期望得到什麼回報?你能否也顯示你的PHP代碼? – mccannf

+0

嘿mccannf,我期待這件事返回''。我將用php代碼編輯我的帖子。 – pufAmuf

回答

1

這是一個瀏覽器附加到一個文本字符串和警報顯示數據時如何處理XML對象。你的ajax調用看起來像是在工作。

你可以嘗試改變:

success: function (html) { // this happens after we get results 
     alert("Data Loaded: " + html); 
    }, 

只是:

success: function (html) { // this happens after we get results 
     console.log(html); 
    }, 

和查看對象的JavaScript控制檯。 或者:

success: function (html) { // this happens after we get results 
     var xmlString = (new XMLSerializer()).serializeToString(html); 
     alert("Data loaded: " + xmlString); 
    },