我正在尝试使用 jquery.ajax查询http://developer.pintlabs.com/brewerydb/api-documentation 。
这是我尝试过的两个 Jquery 请求(注意“O3tmVI”是一个虚拟 ID):
$.ajax({
url:"http://api.playground.brewerydb.com/beer/" + "O3tmVI" + "?key=A1029384756B&format=json",
dataType: "jsonp",
jsonpCallback: "callbackfunctie",
success:function(oData){
var returnData = oData;
console.log(returnData);
}
});
和:
$.getJSON("http://api.playground.brewerydb.com/beer/" + "O3tmVI" + "?key=A1029384756B&format=json&jsoncallback=?",
function(data){
console.log(data);
});
两者都会导致此错误:
Uncaught SyntaxError: Unexpected token :
现在,返回的 json 对象如下所示:
{"message":"Request Successful","data":{"id":"O3tmVI","name":"The Public","description":"The Public\u2122 is a delicious easy drinking pale ale made from a simple recipe of quality grain and top notch American hops. Tawny hues of caramel and amber are a trademark of the Public ale as well as a delicious spruce crispness resulting from a beautiful abundance of hops! This beer will be produced throughout the year and serves as the foundation of our product line.","abv":"6","glasswareId":8,"availableId":1,"styleId":33,"isOrganic":"N","labels":{"icon":"http:\/\/s3.amazonaws.com\/brewerydbapi\/beer\/O3tmVI\/upload_3sdJcU-icon.png","medium":"http:\/\/s3.amazonaws.com\/brewerydbapi\/beer\/O3tmVI\/upload_3sdJcU-medium.png","large":"http:\/\/s3.amazonaws.com\/brewerydbapi\/beer\/O3tmVI\/upload_3sdJcU-large.png"},"status":"verified","statusDisplay":"Verified","servingTemperature":"cool","servingTemperatureDisplay":"Cool - (8-12C\/45-54F)","createDate":"2012-04-05 04:02:36","updateDate":"2012-04-05 04:34:17","glass":{"id":8,"name":"Tulip","createDate":"2012-04-05 04:00:04"},"available":{"id":"1","name":"Year Round","description":"Available year round as a staple beer."},"style":{"id":33,"categoryId":10,"category":{"id":10,"name":"American Ale","bjcpCategory":"10","createDate":"2012-04-05 04:00:04"},"bjcpSubcategory":"A","name":"American Pale Ale","simpleUrl":"american-pale-ale","ibuMin":"30","ibuMax":"45","abvMin":"4.5","abvMax":"6.2","srmMin":"5","srmMax":"14","ogMin":"1.045","ogMax":"1.06","fgMin":"1.01","fgMax":"1.015","createDate":"2012-04-05 04:00:04"}},"status":"success"}
我已成功将其验证为有效的 JSON
现在,问题是我需要一个 JSONP 对象才能请求它(跨域)。所以它必须被包装在一个容器函数中。使用请求中的参数应该可以做到这一点,但是到目前为止,我几乎尝试了任何方法,但都没有成功...
我发现这篇文章有一个关于这个错误的简短条目:http ://www.jquery4u.com/json/ajaxjquery-getjson-simple/
Uncaught SyntaxError: Unexpected token :(in crome) Invalid Lable(in firefox) “invalid label” 错误可以通过将 JSON 数据传递给 js 回调来修复
但我真的不明白他在说什么
我究竟做错了什么?