Mariano
Mariano

Reputation: 221

Parse data from xml to be used in jQuery

I'm writing a currency exchange widget and i can't get how to parse data from this xml: http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml

Here's my code:

jQuery('#value_from').on('keyup', function() {
    var data = this.value;
    var curr = document.getElementById('curr_from').value;
    jQuery.ajax({
        type: "GET",
        url: "http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml",
        dataType: "xml",
        success: function(xml) {
            jQuery(xml).find('Cube').each(function(){
                var data = jQuery(this).attr('currency');
                console.log(data);
            });
        }
    });
    document.getElementById('value_to').value = '\u20AC ' + data;
});

Upvotes: 0

Views: 195

Answers (1)

Jai
Jai

Reputation: 74738

change this:

jQuery(xml).find('cube')

to this:

jQuery(xml).find('Cube')
    //------------^-------uppercase 'C'

In your xml file i just seen that you have the xml node as Cube but you are finding it with lowercase c as cube.


Note:

As this is a cross domain data access hence dataType:"xml" won't work here, as per docs cross domain data can be accessed only with dataType:"jsonp".

Upvotes: 1

Related Questions