Skip to content

Instantly share code, notes, and snippets.

@MPJHorner
Created August 11, 2016 14:37
Show Gist options
  • Save MPJHorner/2d7b755854129d9e410c5ca38681fbaa to your computer and use it in GitHub Desktop.
Save MPJHorner/2d7b755854129d9e410c5ca38681fbaa to your computer and use it in GitHub Desktop.
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