Created
June 25, 2018 08:03
-
-
Save manmeetsingh7781/d7d2ec022e8cbdc78e8a65a3ab1516f8 to your computer and use it in GitHub Desktop.
Quote Api
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 id="new-quote"></div> | |
<script> | |
var body = document.getElementById("new-quote") | |
var url = "https://site-manmeetsingh7781.c9users.io/api/endpoint" | |
var xml = new XMLHttpRequest(); | |
xml.onreadystatechange = function(){ | |
if(xml.readyState === 4 && xml.status === 200){ | |
var data = JSON.parse(xml.responseText); | |
function rand(){ | |
var random = Math.floor(Math.random() * data.length); | |
$(body).append(data[random].quote+ "<p>— " + data[random].name + "</p>") | |
console.log(data[random].quote + " - " + data[random].name) | |
} | |
rand(); | |
} | |
} | |
xml.open("GET",url); | |
xml.send(); | |
</script> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is public API to get a random quote