Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <h3> Returns Country of Origin from users IP Address</h3>
- <p id="demo"></p>
- <script>
- function profileloader()
- {
- profile = []; // no "var" makes this global in scope
- profile[0] = "Joe";
- profile[1] = "Bloggs";
- profile[2] = "images/joeb/pic.jpg";
- profile[3] = "Web Site Manager";
- }
- profileloader(); // mandatory
- document.write("Firstname is: " + profile[0]);
- function pressme(){
- $.getJSON('//freegeoip.net/json/?callback=?', function (data) {
- console.log(JSON.stringify(data, null, 2));
- //Testing to see if response returns correctly
- var response = (data);
- console.log(response);
- resultArray = [];
- resultArray[0] = response.country_name;
- console.log(resultArray[0]);
- document.getElementById("demo").innerHTML = response.country_name;
- });
- }
- pressme();
- document.write("Country is: " + resultArray[0]);
- </script>
Add Comment
Please, Sign In to add comment