我尝试使用此Zipcode Distance和Radius API:https://zipcodedistanceapi.redline13.com 但我收到错误" 未捕获的SyntaxError:意外的令牌:"这可以防止将数据发送到控制台日志。但是,如果我点击"来源"在chrome的开发者工具中,我可以看到坐在那里的数据(不是在控制台中,而是在其他地方):
{"zip_codes":[{"zip_code":"19801","distance":0.009},{"zip_code":"19802","distance":0.009},{"zip_code":"19803","distance":0.009},{"zip_code":"19804","distance":0.009},{"zip_code":"19805","distance":0.009},{"zip_code":"19806","distance":0.009},{"zip_code":"19807","distance":0.009},{"zip_code":"19808","distance":0.009},{"zip_code":"19809","distance":0.009},{"zip_code":"19810","distance":0.009},{"zip_code":"19850","distance":0.009},{"zip_code":"19880","distance":0.009},{"zip_code":"19884","distance":0.009},{"zip_code":"19885","distance":0.009},{"zip_code":"19886","distance":0.009},{"zip_code":"19890","distance":0.009},{"zip_code":"19891","distance":0.009},{"zip_code":"19892","distance":0.009},{"zip_code":"19893","distance":0.009},{"zip_code":"19894","distance":0.009},{"zip_code":"19895","distance":0.009},{"zip_code":"19896","distance":0.009},{"zip_code":"19897","distance":0.009},{"zip_code":"19898","distance":0.009},{"zip_code":"19899","distance":0.009},{"zip_code":"19889","distance":0.867}]}
这是我的代码:
var requestURL = 'https://zipcodedistanceapi.redline13.com/rest/2sd1f31DsfsdfsdPfOezWRkmc2Z14HkhGGuCAycWqP6N7ADmoRWkJgGVi/radius.json/19803/2/mile';
$.ajax({
url: requestURL,
dataType: "jsonp", // will automatically add "?callback=jqueryXXX"
jsonpCallback: 'callback',
type: "get",
success: function(data) {
console.log(data);
}
});
我已经看到stackoverflow上的一些帖子与此类似,但它们似乎都没有解决我的问题。也许它特定于此API。