利用腾讯api逆解析地址,结果一直没进到success方法,求各位大神帮帮吗
自己写的ajax代码:
$.ajax({ url: 'http://apis.map.qq.com/ws/geocoder/v1/?location=30.464149,114.424744&key=GLHBZ-BBN34-SHIUX-XTORD-5RIHZ-ACFAO&get_poi=1', type: 'GET', dataType: 'JSONP', timeout: 1000, success: function (data) { var address = data.result.address; console.log("qq address:"+ address); sessionStorage.setItem("myAddress", address); alert('http://apis.map.qq.com/ws/geocoder/v1/?location='+lat+','+lng+'&key=GLHBZ-BBN34-SHIUX-XTORD-5RIHZ-ACFAO&get_poi=1'); }, error: function (err) { alert("shibai"); alert('http://apis.map.qq.com/ws/geocoder/v1/?location='+lat+','+lng+'&key=GLHBZ-BBN34-SHIUX-XTORD-5RIHZ-ACFAO&get_poi=1'); alert("error:"+err.status) sessionStorage.setItem("myAddress", address); } });
不明白为啥总是进不到success方法;
自己写了个ajax页面:
<body>
<button id="b01" type="button">改变内容</button>
<script type="text/javascript">
$("#b01").click(
function (){
$.ajax({
url: 'http://apis.map.qq.com/ws/geocoder/v1/?location=30.464149,114.424744&key=GLHBZ-BBN34-SHIUX-XTORD-5RIHZ-ACFAO&get_poi=1',
type: 'GET',
dataType: 'jsonp',
success: function (data) {
var address = data.result.address;
console.log("qq address:"+ address);
alert('http://apis.map.qq.com/ws/geocoder/v1/?location='+lat+','+lng+'&key=GLHBZ-BBN34-SHIUX-XTORD-5RIHZ-ACFAO&get_poi=1');
},
error: function (err) {
alert("shibai");
alert('http://apis.map.qq.com/ws/geocoder/v1/?location='+lat+','+lng+'&key=GLHBZ-BBN34-SHIUX-XTORD-5RIHZ-ACFAO&get_poi=1');
alert("error:"+err.status);
sessionStorage.setItem("myAddress", address);
}
});
}
);
</script>
</body>
但是请求后看控制台输出:
?location=30.464149,114.424744&key=GLHBZ-BBN34-SHIUX-XTORD-5RIHZ-ACFAO&get_poi=1&callback=jQuery110…:2 Uncaught SyntaxError: Unexpected token :
不知道为啥会出现callback的参数,搞不明白啊
帮你看了api,发现api默认返回的是json,你要返回jsonp的话,得在URL后面加上