【发布时间】:2018-01-06 17:26:04
【问题描述】:
我无法从Random quote API 中获取值。我不知道这个问题发生在哪里。是在获取内容时还是在将其返回到前端时。如果我可以访问日志,本可以弄清楚。而且,我在互联网上免费找到了这个 API。我仍然不明白回调参数的作用。
请参考下面的屏幕截图
这是我的html代码
$(document).ready(function() {
$("#click").on("click", function() {
$.getJSON("http://quotesondesign.com/wp-json/posts?filter[orderBy]=rand&filter[posts_per_page]=1&callback=", function(key) {
$("#quote").append(key[0].content + "<br><p> - " + key[0].title + "</p>");
});
});
});
.position-message {
margin-left: 25%;
margin-right: 25%;
margin-top: 10%;
margin-bottom: 20%;
}
.background {
background-color: maroon;
}
.button-shape {
border-radius: 50%;
width: 50px;
height: 50px;
margin: auto;
}
.fa-size {}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" href="//fonts.googleapis.com/css?family=Open+Sans:300,400,600,700&lang=en" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<div class="container-fluid">
<div id="quote" class="well position-message"></div>
<br>
<br>
<div class="row text-center">
<button type="button" id="click" class="button-shape"><i class="fa fa-refresh fa-2x"></i></button>
</div>
</div>
以下是我网页的快照。每当单击按钮时,我都会尝试在白色区域<div id="quote" class="well position-well"> 中打印随机报价。
【问题讨论】:
标签: javascript jquery html json ajax