站长资源
中国站长网站

巧用百度地图接口,获取当前城市附带IP检测

效果如下:

代码如下:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>检测ip和地区</title>
</head>
<script src="https://cdn.bootcss.com/jquery/1.9.1/jquery.min.js"></script>
<style type="text/css">
		.box{text-align: center;}
	</style>
<body>
<div class="box">
<h1>AJAX检测ip和地区</h1>
<p id="city"></p>
<p id="ip"></p>
</div>
</body>
</html>
<script type="text/javascript">
$(function(){
	//获取城市ajax
	$.ajax({
	url: 'http://api.map.baidu.com/location/ip?ak=ia6HfFL660Bvh43exmH9LrI6',  
	type: 'POST',  
	dataType: 'jsonp',
	success:function(data) {  
		console.log(JSON.stringify(data.content.address_detail.province + "," + data.content.address_detail.city));
		$('#city').html(JSON.stringify(data.content.address_detail.province + "," + data.content.address_detail.city))
	}
	});
	//获取ip ajax
	$.ajax({
	    url: 'http://ip-api.com/json',
	    success: function(data){
	       console.log(JSON.stringify(data.query));
	       $('#ip').html(JSON.stringify(data.query))
	    },
	    type: 'GET',
	    dataType: 'JSON'
	});
})

</script>

本文出处:来自互联网信息共享,请勿相信收费信息站长资源 » 巧用百度地图接口,获取当前城市附带IP检测

评论 抢沙发

评论前必须登录!