I have attempted various solutions I have seen in other questions, but am not successfully logging data.ip
.
When I log foo
I only return undefined
. Why is the ip
property not being logged with async
set to false
?
TY
$.ajaxSetup({
async: false
});
var getIp = function() {
var ip;
$.getJSON('//freegeoip.net/json/?callback=?', function(data) {
ip = data.ip;
});
return ip;
}
var foo = getIp();
console.log(foo);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>