我正在尝试创建一个随机引用生成器,并且我已将GET请求与按钮相关联。我对API很无能为力这是我的第一次尝试,我希望有人指出我的错误。这是我的代码:
$("#randomQuote").on('click', function() {
$.ajaxSetup({
cache: false
});
$.getJSON("http://quotesondesign.com/wp-json/posts?filter[orderby]=rand&callback=", function(data) {
$(".messageQuote").html(data[0].content + " - " + data[0].title)
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<h1 class="text-center">random quotes</h1>
<div class="container">
<div class="well col-xs align-self-center messageQuote text-center">
<button id="randomQuote" type="button">random quote</button>
</div>
</div>