检索JSON抛出错误:意外标记: [英] Retrieving JSON throws error: Unexpected token :

查看:124
本文介绍了检索JSON抛出错误:意外标记:的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过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

这篇关于检索JSON抛出错误:意外标记:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆