Skip to content

Instantly share code, notes, and snippets.

@waldothedeveloper
Created May 18, 2018 12:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save waldothedeveloper/422c9f80af8be0d3e1633f9af3f46c50 to your computer and use it in GitHub Desktop.
Save waldothedeveloper/422c9f80af8be0d3e1633f9af3f46c50 to your computer and use it in GitHub Desktop.
Making a getJSON request to the forismatic API and showing the data back in the HTML card.
$(document).ready(() => {
let endpoint = 'https://api.forismatic.com/api/1.0/?method=getQuote&lang=en&format=jsonp&jsonp=?';
let getRandomQuote = () => {
$.getJSON(`${endpoint}`, (data) => {
$("#quote").html(`<i class="fas fa-quote-left"></i> ${data.quoteText} <i class="fas fa-quote-right"></i>`);
//Checking if the quote does not have an author
if (data.quoteAuthor !== "") {
$("#quote-author").html(`${data.quoteAuthor} at <a href="${data.quoteLink}" target="_blank" class="card-link">forismatic</a>`);
} else {
$("#quote-author").html(`Unknown at: <a href="${data.quoteLink}" target="_blank" class="card-link">forismatic</a>`);
}
});
});// end of document.ready
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment