2013-03-15 111 views
0

我新的Ajax和XML與jQuery解析和我與它一點點問題。我不想從這裏的非本地xml文件檢索數據:http://www.velib.paris.fr/service/carto/carto.xml。 在阿賈克斯,我這個編碼。使用jQuery的Ajax處理XML文件

$.ajax({ 
    type: 'GET' , 
    url: 'http://www.velib.paris.fr/service/carto/carto.xml' ,  
    success: function(xml) { 
     console.log('Success') ; 
     console.log(xml) ;    
    } , 
    error: function() { 
     console.log('Error') ; 
    } 
}) ; 

但是,在「執行console.log(XML)在它返回的HTML標記的字符串的是,它明確XML(通過擴展,並且當u去頁面我提到上面)。也許我做錯了什麼,所以我需要幫助,請:) :)

回答

1

通過dataType: "xml"到ajax調用,以便jQuery可以解析響應文本爲xml並將結果傳遞給成功回調

$.ajax({ 
    type: 'GET' , 
    url: 'http://www.velib.paris.fr/service/carto/carto.xml' ,  
    dataType: 'xml', 
    success: function(xml) { 
     console.log('Success') ; 
     console.log('Success found maker: ' + jQuery(xml).find('marker').length) ; 
     console.log(xml) ;    
    } , 
    error: function() { 
     console.log('Error') ; 
    } 
}) ; 
+0

控制檯日誌仍然返回「Object {responseText:」對於J ... rator「/>」}「。 – phndiaye 2013-03-15 12:48:07

+0

不,它是一個xml對象,你可以像查詢'console.log('成功找到製造商:'+ jQuery(xml).find('marker')。length);' – 2013-03-15 13:00:28

+0

我在網站上試過它工作正常 – 2013-03-15 13:01:06