I'm trying to set the global variable countryCode. But the value is always null. What can I do? I tried many ways. PLS HELP!
function GetGeolocation(){
$.getJSON("http://ip-api.com/json/?callback=?",function(data){
$.each(data, function(k, v) {
table_body += "<tr><td>" + k + ": " + "</td><td><b>" + v + "</b></td></tr>";
if (k == "countryCode")
{
SetGeolocation(v);
}
})
});
}
function SetGeolocation(value){
countryCode = value;
console.log(countryCode); //Value
}
function Result(){
console.log(countyCode); //Null
}
$(document).ready(function(){
GetGeolocation();
Result();
});