Last active
February 8, 2019 18:07
-
-
Save kyletaylored/2ff2b633269a3006dd75c472802d1515 to your computer and use it in GitHub Desktop.
Get public ip location data using jQuery or Vanilla JS
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
// jQuery | |
(function($) { | |
$(document).ready(() => { | |
$.get("https://ipinfo.io/json").done((loc) => { | |
console.log(loc); | |
}); | |
}) | |
})(jQuery); | |
// Fetch (VanillaJS) | |
fetch("https://ipinfo.io/json").then((resp) => { | |
resp.text().then((body) => { | |
console.log(body); | |
}); | |
}); | |
/* | |
SAMPLE RESULTS | |
{ | |
"ip": "70.118.23.162", | |
"hostname": "rrcs-70-118-23-162.sw.biz.rr.com", | |
"city": "Coppell", | |
"region": "Texas", | |
"country": "US", | |
"loc": "32.9673,-96.9805", | |
"postal": "75019", | |
"org": "AS11427 Charter Communications Inc" | |
} | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment