RandomQuoteMachine - how to refresh API data

i have a trouble figuring out how to refresh API data … any suggestions?

http://codepen.io/xd/pen/LWBqoN

thank you ! :slight_smile:

Use .html() instead of .append(), otherwise each new quote is appended on the screen.

If you have a problem getting different data each time (you get a result from your cache) then use:

$.ajaxSetup({
    cache:false
});
3 Likes
Another interesting way is to set timer - interval in which you can
reload data :slight_smile:

$(document).ready(function() {
  function getQuote(){
      setInterval(function(){
          $.getJSON("http://api.forismatic.com/api/1.0/?method=getQuote&lang=en&format=jsonp&jsonp=?", 
           function(json) {
                $("h3").html(json.quoteText);
                $("h4").html("Author: " + json.quoteAuthor);
           }, "json");
    }, 3000);
  }
  $("button").on('click', function() {
     getQuote();
  }); 
});

It will set timer to 3000 ms = 3 seconds which will then refresh your data too.

1 Like

I dont know how long this has bothered me, until you came my way dear Sir. THank you!!!