检索JSON抛出错误:意外标记:抛出、标记、意外、错误

2023-09-10 21:17:00 作者:路途满棘

我通过AJAX检索从谷歌地图API的高程数据。

I'm retrieving the elevation data from the Google Maps API by AJAX.

我收到数据后,我想,如果我看在Chrome的控制台,我可以看到一个200状态code,可以看到在响应选项卡中的数据。但抛出了未捕获的SyntaxError:意外的标记:这样我就可以不显示从JSON文件什么

I'm getting the data back I want as if I look at the console in Chrome I can see a 200 status code and can see the data in the response tab. But is throws up 'Uncaught SyntaxError: Unexpected token :' so I can't display anything from the JSON file.

这是我的code:

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);
        }
    });

本次现场code是在这里: HTTP://map.colouring$c$c。 COM /

所有的帮助是极大的AP preciated。

All help is greatly appreciated.

推荐答案

在谷歌地图API不支持直接JSONP请求。

The Google Maps API does not support direct JSONP requests.

相反,你需要使用的JavaScript API

 
精彩推荐
图片推荐