我正在通过AJAX从Google Maps API检索高程数据。正在检索JSON抛出错误:意外的令牌:
我正在收回数据,我希望看到Chrome中的控制台我可以看到200状态代码,并可以在响应选项卡中看到数据。但是被抛出'未捕获的SyntaxError:意外的标记:'所以我不能显示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/
所有帮助是极大的赞赏。
那么如果不接受JSONP请求,我该如何获取数据呢? – 2012-02-07 14:48:56
相反,您需要使用[Javascript API](http://code.google.com/apis/maps/documentation/javascript/elevation.html)。 – SLaks 2012-02-07 15:14:14