我正在向Google Maps API发送带有jQuery的AJAX请求。但是,它似乎返回了格式错误的JSON(或者我得到了错误)。
这是我的函数调用:
jQuery.ajax({url: "https://maps.googleapis.com/maps/api/distancematrix/json",
data: {mode: "driving",
units: "imperial",
origins: start_point,
destinations: end_point},
async: false,
dataType: 'jsonp',
crossDomain: true}).responseText
我收到此错误:
Uncaught SyntaxError: Unexpected token :
这就是响应的样子(我替换了隐私的大部分实际值):
{
"destination_addresses" : [ "end_address" ], // this line is highlighted for the error
"origin_addresses" : [ "start_address" ],
"rows" : [
{
"elements" : [
{
"distance" : {
"text" : "some_distance",
"value" : some_number
},
"duration" : {
"text" : "some_time",
"value" : another_number
},
"status" : "OK"
}
]
}
],
"status" : "OK"
}
有什么方法可以解决这个问题吗?我以为我可以以某种方式阻止jQuery检查错误,但我不确定。