</div>
</div>
<div class="grid--cell mb0 mt4">
<a href="/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call" dir="ltr">How do I return the response from an asynchronous call?</a>
<span class="question-originals-answer-count">
(38 answers)
</span>
</div>
<div class="grid--cell mb0 mt8">Closed <span title="2014-03-18 06:50:24Z" class="relativetime">6 years ago</span>.</div>
</div>
</aside>
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);
});
}
</div>
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