I want to use some variables outside the jquery function, but I am failing to make them global. I have followed the advice to first 'var' them and then assign them, but the last log() returns undefined.
var lat,lon;
$.get('ip.json',function(data) {
var loc=data['loc'];
lat=loc.split(',')[0];
lon=loc.split(',')[1];
},'json');
console.log(lat,lon);
UPDATE Here is the full code
var lat,lon;
$.get('ip.json',function(data) {
console.log(data);
var city=data['city'];
var loc=data['loc'];
lat=loc.split(',')[0];
lon=loc.split(',')[1];
$('body').append(' '+city+' '+lat+' '+lon);
},'json');
console.log(lat,lon);
$.get('apiurl?lat='+lat+'&lon='+lon+'&callback=test',function(data) {},'json'),