Created
February 1, 2018 21:31
-
-
Save nickihastings/edbedf8166fa6862a98007031215fbc8 to your computer and use it in GitHub Desktop.
ajax code used to import a JSON API for random quote machine
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(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