我正在编写货币兑换小部件,但我无法解析如何解析此xml中的数据: http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml
这是我的代码:
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;
});
答案 0 :(得分:1)
改变这个:
jQuery(xml).find('cube')
到此:
jQuery(xml).find('Cube')
//------------^-------uppercase 'C'
在您的xml文件中,我刚看到您将xml节点设置为多维数据集,但您发现它使用小写c
作为多维数据集。
由于这是跨域数据访问,因此dataType:"xml"
无法在此处工作,因此根据文档,只能使用dataType:"jsonp"
访问跨域数据。