Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/kubernetes/5.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文件以跟踪用户并提醒数据_Javascript_Geoip - Fatal编程技术网

如何创建外部javascript文件以跟踪用户并提醒数据

如何创建外部javascript文件以跟踪用户并提醒数据,javascript,geoip,Javascript,Geoip,我在html页面中使用这段代码,但我需要一个单独的javascript文件来提醒数据 实际上,应该在html文件中创建一个变量,并将其发送到.js文件,该文件会提醒数据 但我无法将城市名称存储在变量中 <html> <head> <title>home</title> <script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min

我在html页面中使用这段代码,但我需要一个单独的javascript文件来提醒数据

实际上,应该在html文件中创建一个变量,并将其发送到.js文件,该文件会提醒数据

但我无法将城市名称存储在变量中

<html>
    <head>
        <title>home</title>
        <script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script>
        <script src="//j.maxmind.com/js/apis/geoip2/v2.0/geoip2.js"></script>

        <script>
            geoip2.cityISPOrg(function (response) {
                $("#country").html(response.country.names.en);
            }, null, { w3cGeolocationDisabled: true });
        </script>
    </head>
    <body>
        <p>
            <span id="country"></span>,
        </p>
    </body>
</html>
它的报警未定义,它未报警国家值,我认为国家值未存储在变量中。
谁能告诉我如何将值存储在变量中。

你是说这样的吗

<html>
    <head>
        <title>home</title>
        <script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script>
        <script src="//j.maxmind.com/js/apis/geoip2/v2.0/geoip2.js"></script>

        <script>
            geoip2.cityISPOrg(function (response) {
                $("#country").html(response.country.names.en);
            }, null, { w3cGeolocationDisabled: true });
        </script>
    </head>
    <body>
        <p>
            <span id="country"></span>,
        </p>
    </body>
</html>
alert($("#country").html());