Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/423.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 基于GEO-IP的内容显示_Javascript - Fatal编程技术网

Javascript 基于GEO-IP的内容显示

Javascript 基于GEO-IP的内容显示,javascript,Javascript,我在这个页面中添加了下面的代码,这样当人们来自印度时,我可以显示特定的内容。但它并没有按需要发挥作用。在头部 <script> $.get("https://freegeoip.app/json/", function (response) { $("#ip").html("IP: " + response.ip); $("#country_code").h

我在这个页面中添加了下面的代码,这样当人们来自印度时,我可以显示特定的内容。但它并没有按需要发挥作用。在头部

    <script>
            $.get("https://freegeoip.app/json/", function (response) {
    $("#ip").html("IP: " + response.ip);
    $("#country_code").html(response.country_code);
    if(response.country_code=='US'||response.country_code=='UK'||response.country_code=='IN'){
        document.getElementById(response.country_code).style.display = "block";
    }
}, "jsonp");
        </script>
        <style>
            #US {display:none;}
            #UK {display:none;}
            #IN {display:none;}
        </style>

$.get(”https://freegeoip.app/json/“,功能(响应){
$(“#ip”).html(“ip:+response.ip”);
$(“#国家代码”).html(response.country_代码);
if(response.country_code=='US'| | response.country_code==''UK'| | response.country_code==''IN'){
document.getElementById(response.country\u code).style.display=“block”;
}
}“jsonp”);
#US{显示:无;}
#UK{显示:无;}
#在{display:none;}
&在正文部分

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
                                        <div id="ip">Loading...</div>
<div id="country_code"></div>
<div id="US">THE US</div>
<div id="UK">THE UK</div>
<div id="IN">THE IN</div>

加载。。。
美国
英国
在

请帮助输入正确的代码。目前可以查看此内容

您正在尝试在加载jQuery的API之前使用它。只需将jQuery CDN移到嵌入代码的顶部即可


$.get(”https://freegeoip.app/json/“,功能(响应){
$(“#ip”).html(“ip:+response.ip”);
$(“#国家代码”).html(response.country_代码);
如果(response.country_code=='US'
||response.country_code==“英国”
||response.country_code=='IN'){
document.getElementById(response.country\u code).style.display=“block”;
}
}“jsonp”);

“但它没有按需要工作”-我们应该知道为什么它“不工作”,到底是因为什么?(控制台中)是否有任何错误?会发生什么?什么事没有发生?相反会发生什么?当我们加载页面时,显示的是来自印度的内容,但没有显示针对该国的内容。-这辆车停了下来。