Created
February 13, 2018 11:23
-
-
Save jw-jenrise/25cf60ec05a39dbb665d5de0443ea9fb 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
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