Consumes the api from www.mashape.com/andruxnet/random-famous-quotes to generate random quotes
Created
January 13, 2017 09:12
-
-
Save RemLampa/5962a1bfdffe81ece4421939352f4539 to your computer and use it in GitHub Desktop.
Random Quotes Generator
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
<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> |
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
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('"' + quote.quote + '"'); | |
$('.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(); | |
}); | |
}); |
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
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> |
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
.quoteButton { | |
margin: 25px 0; | |
} | |
h4 { | |
padding: 0 10px; | |
} | |
div { | |
margin: 150px; | |
} |
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
<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