【发布时间】:2019-03-06 10:50:40
【问题描述】:
这是我第一次尝试使用简单的 API 却无法获得好的结果。我在这里使用了一个示例:Write something that can read this API Url 结果,我所做的每一次更改都给了我 4,而控制台中什么也没有。 拜托,能给我一个提示吗?
谢谢!
<!DOCTYPE html>
<html>
<body>
first
<div id="fastest">
<script> fetch("https://bitcoinfees.earn.com/api/v1/fees/recommended") // Call the fetch function passing the url of the API as a parameter
.then((resp) => resp.json()) // Transform the data into json
.then(function(data) {
// Your code for handling the data you get from the API
document.write(data.fastestFee); //And since it is just an object you can access any value like this
})
.catch(function(err) {
// This is where you run code if the server returns any errors (optional)
console.log(err)
});
</script>
</div>
</br>second
<div id="30">
<script> fetch("https://bitcoinfees.earn.com/api/v1/fees/recommended") // Call the fetch function passing the url of the API as a parameter
.then((resp) => resp.json()) // Transform the data into json
.then(function(data) {
// Your code for handling the data you get from the API
document.write(data.halfHourFee); //And since it is just an object you can access any value like this
})
.catch(function(err) {
// This is where you run code if the server returns any errors (optional)
console.log(err)
});
</script>
</div>
</br>3th
<div id="60">
<script>
fetch("https://bitcoinfees.earn.com/api/v1/fees/recommended") // Call the fetch function passing the url of the API as a parameter
.then((resp) => resp.json()) // Transform the data into json
.then(function(data) {
// Your code for handling the data you get from the API
document.write(data.hourFee); //And since it is just an object you can access any value like this
})
.catch(function(err) {
// This is where you run code if the server returns any errors (optional)
console.log(err)
});
</script>
</div>
</body>
</html>
【问题讨论】: