我正在通过 AJAX 从 Google Maps API 检索海拔数据。
我正在获取我想要的数据,就像我在 Chrome 中查看控制台一样,我可以看到 200 状态代码,并且可以在响应选项卡中看到数据。但会抛出“Uncaught SyntaxError: Unexpected token :”,因此我无法显示 JSON 文件中的任何内容。
这是我的代码:
var theURL = 'http://maps.googleapis.com/maps/api/elevation/json?locations=' + longitude + ',' + latitude + '&sensor=false&callback=?';
$.ajax({
url: theURL,
type: 'get',
dataType: 'json',
cache: false,
crossDomain: true,
success: function (data) {
var theData = $.parseJSON(data);
console.log(theData);
}
});
实时代码在这里:http://map.colouringcode.com/
非常感谢所有帮助。
最佳答案
Google Maps API 不支持直接 JSONP 请求。
相反,您需要使用 Javascript API .
关于javascript - 检索 JSON 会引发错误 : Unexpected token :,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9177947/