Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
ajax code used to import a JSON API for random quote machine
$(document).ready(function(){
//get the quote api information with Ajax
getQuote();
function getQuote(){
$.ajax({
url: "https://andruxnet-random-famous-quotes.p.mashape.com/?cat=movies&count=1",
type: "GET",
data: {},
dataType: "json",
beforeSend: function(xhr) {
xhr.setRequestHeader("X-Mashape-Authorization", "xYdGlgmLb6mshjBkNyNcbyQpGZuLp17o5c4jsnMmdf7VIAQut0"); // My Mashape key
},
success: function (data){
console.log(data);
$('.quoteline').html(data.quote);
$('.author').html(data.author);
},
error: function(err) { console.log("Failure!..."); console.log(err); }
});
}
$("#nextQuote").on("click", function(e){
e.preventDefault();
getQuote();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment