
这是一款非常简单实用的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>










暂无评论内容