时间:2023-04-21 09:54:01 | 来源:网站运营
时间:2023-04-21 09:54:01 来源:网站运营
PageAdmin网站建设教程:仿58同城站群系统实现不同地区Ip跳转不同分站:很多大型信息平台,如58同城,百姓网等都会有全国地区分站,比如我杭州的,打开58同城会自动进入杭州分站。{"code":0,"data":{"ip":"210.73.44.249","country":"中国","area":"","region":"广东","city":"杭州","county":"XX","isp":"科技网","country_id":"CN","area_id":"","region_id":"440000","city_id":"440100","county_id":"xx","isp_id":"1000114"}}下面我们通过ajax请求的方式来获取到归属信息实现跳转,代码如下:
<script type="text/javascript">var clientIp = "@StringHelper.GetClientIP()";//调用pageadmin的内置方法获取ip地址var api="http://ip.taobao.com/service/getIpInfo.php";$(function () {$.ajax({url: api,type: "GET",dataType: "json",data: { ip:clientIp },success: function (ipData) {ipData = JSON.parse(ipData)var city = ipData.data.city;cityDomain(city)}});});//城市判断function cityDomain(string city){var domain= "www.58.com"; //换成自己的域名switch (city){case "杭州":domain = "guangzhou.58.com";break;case "杭州":domain = "beijing.58.com";break;case "其他地区一一判断"://更多break;}location.href = "domain";}</script>
关键词:实现,地区,系统,建设,教程