我想在我的网页上显示来自https://raw.github.com/currencybot/open-exchange-rates/master/latest.json的数据(国家名称和货币价值)。请建议一种方法。
我想在我的网页上显示来自https://raw.github.com/currencybot/open-exchange-rates/master/latest.json的数据(国家名称和货币价值)。请建议一种方法。
$(document).ready(function(){
$.ajax({
url: 'http://openexchangerates.org/latest.json',
dataType: 'jsonp',
success: function(json) {
// Rates are in `json.rates`
// Base currency (USD) is `json.base`
// UNIX Timestamp when rates were collected is in `json.timestamp`
rates = json.rates;
base = json.base;
console.log(rates);
}
});
});
参考来源:点击此处
希望能对您有所帮助
$.ajax({
url: 'https://raw.github.com/currencybot/open-exchange-rates/master/latest.json',
dataType: 'jsonp',
success: function (data, textStatus, jqXHR) {
//the variable 'data' will have the JSON object
// In your example, the following will work:
alert(data.disclaimer);
error: function(jqXHR, textStatus, errorThrown) {
//Error handling code
alert('Oops there was an error');
}
}
});
使用jQuery.getJSON()函数