phndiaye
phndiaye

Reputation: 329

Using jQuery Ajax to deal with xml file

I'm new to Ajax and Xml parsing with jQuery and i have a little problem with it. I wan't to retrieve datas from a non local xml file here : http://www.velib.paris.fr/service/carto/carto.xml . In Ajax, i coded this :

$.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') ;
    }
}) ;

But, the "console.log(xml) is returning a string with html tags in it. yet, it's clearly xml (by the extension, and when u go the page i mentionned above). Maybe i'm doing something wrong, so i need help, please :)

Upvotes: 0

Views: 143

Answers (1)

Arun P Johny
Arun P Johny

Reputation: 388316

Pass dataType: "xml" to the ajax call, so that jQuery can parse the response text as xml and pass the result to the success callback

$.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') ;
    }
}) ;

Upvotes: 1

Related Questions