网址http://smart-ip.net/geoip-json包含一个JSON,其中包含有关地理位置的数据.
我想将该JSON文件存储在JavaScript变量中,因此我可以使用此JSON的字段.
小智 6
这似乎是一个跨域请求.直接读取JSON是有问题的,但您可以使用JSONP.您的链接支持它.你需要这样的东西:
<script type="text/javascript">
  function your_callback(data) {
    // do something with data
    alert('City : '+data.city+' Country name : '+data.countryName);
  }
</script>
<script type="text/javascript" src="http://smart-ip.net/geoip-json?callback=your_callback"></script>?
Run Code Online (Sandbox Code Playgroud)
演示.`