Created
August 11, 2016 14:37
-
-
Save MPJHorner/2d7b755854129d9e410c5ca38681fbaa 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
The API is at https://www.ipify.org/ | |
The API endpoint is https://api.ipify.org?format=json | |
function httpGetAsync(theUrl, callback) | |
{ | |
var xmlHttp = new XMLHttpRequest(); | |
xmlHttp.onreadystatechange = function() { | |
if (xmlHttp.readyState == 4 && xmlHttp.status == 200) | |
callback(xmlHttp.responseText); | |
} | |
xmlHttp.open("GET", theUrl, true); // true for asynchronous | |
xmlHttp.send(null); | |
} | |
function callbackHandler(data){ | |
console.log(data) | |
} | |
Then call it with | |
httpGetAsync('https://api.ipify.org?format=json', callbackHandler) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment