Skip to content

Instantly share code, notes, and snippets.

@Ornataweaver
Created November 12, 2018 10:37
Show Gist options
  • Save Ornataweaver/45d51e061ad990e33750c52662aa69b8 to your computer and use it in GitHub Desktop.
Save Ornataweaver/45d51e061ad990e33750c52662aa69b8 to your computer and use it in GitHub Desktop.
Joke, JSON API, Ajax
<body class="text-center">
<br>
<h2>Jokes that I connected via Ajax:</h2>
<p class="message">
The joke will go here
</p>
<button id="getQuote">
Get Message
</button>
</body>
$(document).ready(function() {
// twttr.widgets.load();
// function getQuote(){}
$("#getQuote").on("click", function(){
var html = "";
$.getJSON("https://api.icndb.com/jokes/random.json", function(obj) {
html += "<div>";
html += obj["value"]["joke"] + "<br>" + "<strong>" + "from 'https://api.icndb.com/jokes/random/' " + "JokeID=" + obj["value"]["id"] + " " + "</strong>" + "<br>" ;
html += "</div>";
$(".message").html(html);
});
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
body {
background: #aa0;
/* text-align: center; */
font-family: monospace;
color: #000;
font-size: 20px;
}
button {
border-radius: 5px;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" rel="stylesheet" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment