Created
December 30, 2015 15:28
-
-
Save MaximilianLloyd/9a83e19388e92819aa64 to your computer and use it in GitHub Desktop.
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
// step 1. create an element with the class of "message" | |
// Step 2. Insert the code below in a file or script tag | |
var message = document.querySelector('.message'); | |
var xhr = new XMLHttpRequest(); | |
xhr.open("GET", "http://numbersapi.com/random"); | |
xhr.onload = function (e) { | |
if (xhr.readyState === 4) { | |
if (xhr.status === 200) { | |
message.innerHTML = xhr.responseText; | |
} else { | |
console.error(xhr.statusText); | |
} | |
} | |
}; | |
xhr.send() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment