我的这种黑客行为是否有助于从Coindesk的API检索实时数据?我本着极大的热情写了这篇文章,但我希望有专业人士可以帮助编写更清晰的代码?
这会执行预期的吗?
// Request Variable
var rqst = new XMLHttpRequest();
// GET request on the URL endpoint
rqst.open('GET', 'https://api.coindesk.com/v1/bpi/currentprice.json', true);
rqst.onload = function () {
//store JSON in data variable
var data = JSON.parse(this.response);
//loop over data to retrieve specific thing
data.forEach(bpi => {
// do something with data like; append to header in HTML
});
}}
// Send request
rqst.send();