前端获取ip 地址和当前城市信息

获取ip 地址 

fetch('https://api.ipify.org?format=json')
    .then(response => response.json())
    .then(json => console.log(json.ip) )
 
获取 当前城市信息
  var xhttp = new XMLHttpRequest();
  xhttp.onreadystatechange = function () {
    if (this.readyState == 4 && this.status == 200) {
      var response = JSON.parse(xhttp.responseText);
      console.log(response);
    }
  };
  xhttp.open("GET", `http://ip-api.com/json/?lang=zh-CN`, true);
  xhttp.send();
 
当前定位 : http://ip-api.com/json/?lang=zh-CN 
指定ip :  http://ip-api.com/json/8.8.8.8?lang=zh-CN 
切换语言:  lang=zh-CN  

 

https://ipapi.co/json/ 返回英文信息

 

 https://api.vore.top/api/IPdata

 

 

 
 
posted @ 2024-05-23 16:17  cielw  阅读(867)  评论(0)    收藏  举报