jquery.ajaxを使用してhttp://developer.pintlabs.com/brewerydb/api-documentationにクエリを実行しようとしています。
これらは私が試したJqueryリクエストの2つです(「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:予期しないトークン:
これで、返される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コールバックに渡すことで修正できます。
しかし、私は彼がそこで何を言っているのか本当に理解していません
私は何が間違っているのですか?