Skip to content

Instantly share code, notes, and snippets.

@MaximilianLloyd
Created December 30, 2015 15:28
Show Gist options
  • Save MaximilianLloyd/9a83e19388e92819aa64 to your computer and use it in GitHub Desktop.
Save MaximilianLloyd/9a83e19388e92819aa64 to your computer and use it in GitHub Desktop.
// 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