0

What I planned to do is using a 3rd party engine that is able to obtain the ip address of the current user, however I can't seem to store it in a variable.

Here is how I attempt to do it:

http://codepen.io/vincentccw/pen/JoVebG?editors=101

Here is the code I'm using:

$("div").click(function (e) { 
  var ip_ad = '';
  $.get("http://ipinfo.io", function(response) {
        alert("Your ip from get: " +  response.ip);
        storeIP(response.ip);
 }, "jsonp");


function storeIP(data) {
   ip_ad = data;
   alert("Your ip from function: " +  ip_ad);
 }

  console.log("Your ip from global variable: " +  ip_ad);
});

I can alert the ip on each stage, but I can't seem to append the value into my ip_ad variable.

Vincent1989
  • 1,593
  • 2
  • 13
  • 25

0 Answers0