var city;
function getCity(){
$.getJSON("http://ip-api.com/json/?callback=?", function(data) {
city= data.city;
alert(city);
});
}
getCity();
alert(city);
I am alerting the same city variable two times, one inside the function getcity() and another at last. But they both gives different values. Inside the function gives current city but out side the function gives undefined. I want to get current city on both.