Skip to content

Instantly share code, notes, and snippets.

@RemLampa
Created January 13, 2017 09:12
Show Gist options
  • Save RemLampa/5962a1bfdffe81ece4421939352f4539 to your computer and use it in GitHub Desktop.
Save RemLampa/5962a1bfdffe81ece4421939352f4539 to your computer and use it in GitHub Desktop.
Random Quotes Generator
<div class = "text-center">
<h1 class="quote text-center text-primary"></h1>
<h4 class="author text-muted"></h4>
<button class="quoteButton btn btn-lg btn-default" type="button">Random Quote</button>
</div>
function generateQuote() {
$.ajax({
url: 'https://andruxnet-random-famous-quotes.p.mashape.com/cat=famous', // The URL to the API. You can get this by clicking on "Show CURL example" from an API profile
type: 'POST', // The HTTP Method
data: {}, // Additional parameters here
datatype: 'json',
success: function(data) {
quote = JSON.parse(data);
$('.quote').html('&quot;' + quote.quote + '&quot;');
$('.author').html('-= ' + quote.author + ' =-');
},
error: function(err) {
console.log(err);
},
beforeSend: function(xhr) {
xhr.setRequestHeader("X-Mashape-Authorization", "c3Ylhc7ZXbmshY1lb0rYQRiRmLX9p1sJqiYjsnToJMCxt3XNhP"); // Enter here your Mashape key
}
});
};
$(document).ready(function() {
var quote;
generateQuote();
$('.quoteButton').click(function(event) {
generateQuote();
});
});
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
.quoteButton {
margin: 25px 0;
}
h4 {
padding: 0 10px;
}
div {
margin: 150px;
}
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment