Skip to content

Instantly share code, notes, and snippets.

@teleological
Created May 8, 2013 18:13
Show Gist options
  • Save teleological/5542360 to your computer and use it in GitHub Desktop.
Save teleological/5542360 to your computer and use it in GitHub Desktop.
var iphost = "http://api.hostip.info/get_json.php";
var countryhost = "http://api.hostip.info/get_json.php?ip=";
function getIP() {
return $.ajax({
type: 'GET',
url: iphost,
dataType: 'json'
});
}
function countryOf(data) {
return $.ajax({
type: 'GET',
url: countryhost + data.ip,
dataType: 'json'
});
}
function display(data) {
console.log(data.country_name);
}
function showError(xhr, data) {
console.log("Error: " + data);
}
$(document).ready(function () {
getIP()
.then(countryOf)
.then(display, showError)
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment