Skip to content

Instantly share code, notes, and snippets.

@jw-jenrise
Created February 13, 2018 11:23
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/25cf60ec05a39dbb665d5de0443ea9fb to your computer and use it in GitHub Desktop.
Save jw-jenrise/25cf60ec05a39dbb665d5de0443ea9fb to your computer and use it in GitHub Desktop.
function getRemoteData(url){
//var XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest; //Uncomment this line if you are using it in node js environment.
// 1. Create the request
var xhr = new XMLHttpRequest();
// 2. Create the URL
var delay = Math.floor(Math.random() * 9) + 1;
// Open the URL
xhr.open("GET", url + "?delay="+delay, true);
// Specify what should be done after the remote call
xhr.onload = function(){
return (xhr.responseText); // THIS SHOULD RETURN DATA
};
// Initiate call
xhr.send();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment