Skip to content

Instantly share code, notes, and snippets.

@jw-jenrise
Created February 13, 2018 11:22
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 jw-jenrise/878496db140317752a1f908e757b7117 to your computer and use it in GitHub Desktop.
Save jw-jenrise/878496db140317752a1f908e757b7117 to your computer and use it in GitHub Desktop.
function printRemoteData(url, message){
//var XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest; //Uncomment this line if you are using it in node js environment.
var xhr = new XMLHttpRequest();
var delayedUrl = url + "?delay=" + (Math.floor(Math.random() * 9) + 1);
console.log(delayedUrl);
xhr.open("GET", delayedUrl, true);
xhr.onload = function(){
if (message){
console.log(message);
}
console.log (xhr.responseText);
console.log("---------------------");
};
xhr.send();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment