Skip to content

Instantly share code, notes, and snippets.

@Hoxtygen
Created December 30, 2016 18:30
Show Gist options
  • Save Hoxtygen/6339b6da52b070e8c420b00433ac6df5 to your computer and use it in GitHub Desktop.
Save Hoxtygen/6339b6da52b070e8c420b00433ac6df5 to your computer and use it in GitHub Desktop.
how to implement forismatic api
$(document).ready(function() {
var quote;
var author;
function getNewQuote() {
$.ajax({
url: "http://api.forismatic.com/api/1.0/",
jsonp: "jsonp",
dataType: "jsonp",
data: {
method: "getQuote",
lang: "en",
format: "jsonp"
},
success: function(response) {
quote = response.quoteText;
author = response.quoteAuthor;
$("#quote").text(quote);
if (author) {
$("#author").text("By " + author);
} else {
$("#author").text(" ~ Unknown");
}
}
});
}
getNewQuote();
$(".get-quote").on('click', function(event) {
event.preventDefault();
getNewQuote();
});
$(".share-quote").on("click", function(even){
event.preventDefault();
window.open("https://twitter.com/intent/tweet?text=" + encodeURIComponent(quote + "~~ " + author);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment