<!DOCTYPE html>
<html>
<head>
<title>try
</title>
<script type="text/javascript">
window.onload=init;
function jsonpcallback(rs) {
var city = rs['content']['address_detail']['city'];
city = city.toString().substr(0,city.length - 1);
alert(city);
console.log(rs);
}
function init(){
var url = 'http://api.map.baidu.com/location/ip';
var data = {
ak: "你的AK",
coor: "bd09ll",
callback: 'jsonpcallback'
};
var buffer = [];
for (var key in data) {
buffer.push(key + '=' + encodeURIComponent(data[key]));
}
var fullpath = url + '?' + buffer.join('&');
CreateScript(fullpath);
function CreateScript(src){
var el = document.createElement('script');
el.src = src;
el.async = true;
el.defer = true;
document.body.appendChild(el);
}
}
</script>
</head>
<body>
lalalalla
</body>
</html>
转载请注明原文地址: https://www.6miu.com/read-2100312.html