jQuery+Ajax获取当前IP地址和省市地区位置代码

jQuery+Ajax获取当前IP地址和省市地区位置代码-精品资源网
jQuery+Ajax获取当前IP地址和省市地区位置代码
此内容为免费资源,请登录后查看
0
免费资源

jQuery+Ajax获取当前IP地址和省市地区位置代码

这是一款非常简单实用的jQuery+Ajax获取当前IP地址和省市地区位置代码,调用ajax函数获取IP地址和所在省份城市。

js代码

<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://freegeoip.net/json/\',
	    success: function(data){
	       console.log(JSON.stringify(data.ip));
	       $(\'#ip\').html(JSON.stringify(data.ip))
	    },
	    type: \'GET\',
	    dataType: \'JSON\'
	});
})

</script>

© 版权声明
THE END
点赞0 分享
评论 抢沙发
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

取消
昵称表情代码图片

    暂无评论内容