-1

I am able to returned value in alert form from remote php script. However when I console.log(IPAddress) my value is undefined. My Goal is to establish value of IPAddress from json response. Always a single value in json response. Example: {"ip":"192.168.1.1"}

Here is my code:

var IPAddress = function(){
    $.getJSON("http://domain.com/assets/php/get-ip.php/?    callback=DisplayIP",function(data){
                            //alert(result['ip']);

//alert(data.ip);
return(data.ip);
});
}
codemania
  • 1,098
  • 1
  • 9
  • 26

1 Answers1

-1

You need to Parse Json in order to read it. You can do this by using JSON.parse() method.

So, simply use JSON.Parse(data.ip); to get your data

Sai Avinash
  • 4,683
  • 17
  • 58
  • 96