Javascript 地理位置响应国家/地区名称不为';我不在野生动物园工作

Javascript 地理位置响应国家/地区名称不为';我不在野生动物园工作,javascript,jquery,geolocation,country-codes,Javascript,Jquery,Geolocation,Country Codes,我的地理位置响应country_name在Chrome和Firefox中工作,但不在Safari中。我怎样才能解决这个问题 Javascript: $.get("http://freegeoip.net/json/", function (response) { $("#ip").html("IP: " + response.ip); $("#country_code").html(response.country_code); if(response.country_c

我的地理位置响应country_name在Chrome和Firefox中工作,但不在Safari中。我怎样才能解决这个问题

Javascript:

$.get("http://freegeoip.net/json/", function (response) {
    $("#ip").html("IP: " + response.ip);
    $("#country_code").html(response.country_code);
    if(response.country_code=='NL'||response.country_code=='US'){
        document.getElementById(response.country_code).style.display = "block";
    }
}, "jsonp");
HTML:


小提琴手正在High Sierra的最新狩猎活动中工作。我也在Chrome中检查了这个,但它不起作用,因为广告阻止插件阻止了对的请求

为了克服这个问题,您可以在后端创建一个代理(创建一个简单的脚本,它将为您执行GET请求,这样客户机请求将与其原始请求相同)

但是您注意到的错误
页面不允许运行来自freegoip.net/json的不安全内容
与此不同-您正在尝试执行对不安全站点的请求(
http://
而不是
https://

幸运的是,此服务也在https上运行,只需将
s
添加到链接中,它就应该可以工作了

$.get("https://freegeoip.net/json/", function (response) {
    $("#ip").html("IP: " + response.ip);
    $("#country_code").html(response.country_code);
    if(response.country_code=='NL'||response.country_code=='US'){
        document.getElementById(response.country_code).style.display = "block";
    }
}, "jsonp");

你在safari中有一些广告块插件吗?没有活动的广告块。但是,如果我检查该元素,Safari会给出以下错误:[警告][阻止]该页面不允许运行不安全的内容,没有问题,但正如我所指出的,请注意,具有广告阻止的用户也会有类似的问题。克服这一问题的一个可能方法是对后端执行请求,该后端将为您执行该请求。
#NL { display:none;} 
#US { display:none;} 
$.get("https://freegeoip.net/json/", function (response) {
    $("#ip").html("IP: " + response.ip);
    $("#country_code").html(response.country_code);
    if(response.country_code=='NL'||response.country_code=='US'){
        document.getElementById(response.country_code).style.display = "block";
    }
}, "jsonp");