4 ms·
$.ajax({url:"http://freegeoip.net/json", dataType:"json"}) .done(function(data){$('#city').text(data.city)}); freegeoip.net seems to send the "Access-Control
by ajasmin 14y ago
$.ajax({url:"http://freegeoip.net/json", dataType:"json"})
.done(function(data){$('#city').text(data.city)});
freegeoip.net seems to send the "Access-Control-Allow-Origin: *" header which allows the cross-domain ajax call.
Picking a city ~800km from where you are is an exercise left for the reader.
- fountainla 14y agoThis is great. We initially had it in PHP server side, but didn't want to slow down the process. Having it lazy load via ajax is a great idea.