Reputation: 7
The function getQuote successfully populates the quote and author divs with text when the document is ready, but it does not pull a new quote and author on the button click. I tested the button click with an alert function and it works so I'm not sure why the getQuote function has no results.
var quote = "", author = "";
function getQuote() {
$.getJSON("http://quotesondesign.com/wp-json/posts?filter[orderby]=rand&filter[posts_per_page]=1&callback=", function(data) {
quote = data[0].content;
document.getElementById("quote").innerHTML=quote;
author = data[0].title;
document.getElementById("author").innerHTML="- " + author;
});
}
$(document).ready(function() {
getQuote();
$("#button").click(getQuote);
});
Upvotes: 0
Views: 49
Reputation: 7
It turns out to be a cache issue. Problem solved:
$.ajaxSetup({
cache: false
})
Upvotes: 0