2013-03-15 54 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