Skip to content

Instantly share code, notes, and snippets.

@ssaurel
Created July 18, 2019 07:32
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 ssaurel/9e2524f17e12d42a25604be903029a38 to your computer and use it in GitHub Desktop.
Save ssaurel/9e2524f17e12d42a25604be903029a38 to your computer and use it in GitHub Desktop.
Random Fact Web Service Call for the Chuck Norris App in HTML5
function randomFact() {
// We call the Web Service via AJAX
var xmlhttp = new XMLHttpRequest();
var url = "https://api.chucknorris.io/jokes/random";
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
var json = JSON.parse(this.responseText);
// We parse the JSON response
parseJson(json);
}
};
xmlhttp.open("GET", url, true);
xmlhttp.send();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment