简体   繁体   中英

Geo location - JS vs JSON

I am tryign to obtain the geolocation of the user browsing using maxmind's free service http://j.maxmind.com/app/geoip.js

jQuery.getScript('http://j.maxmind.com/app/geoip.js', function() 
{
    var country = geoip_city();
    console.log("Your location is: " + country);
});

However, outputting javascript code instead of a json seems like a bit of a problem, since it evals the code from a site outside your control. What would be the best practice to handle such scenarios?

This will show user's city.

<script type="text/javascript" src="http://j.maxmind.com/app/geoip.js"></script>

<script type="text/javascript">
    document.write(geoip_city());
</script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM