Skip to content

Instantly share code, notes, and snippets.

@nickihastings
Created February 1, 2018 21:31
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 nickihastings/edbedf8166fa6862a98007031215fbc8 to your computer and use it in GitHub Desktop.
Save nickihastings/edbedf8166fa6862a98007031215fbc8 to your computer and use it in GitHub Desktop.
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