0
レシピのURL IDを取得するコールがあります。追加のレシピデータを返すために別のコールにフィードしていますが、範囲が間違っていると思います。JavaScript ajaxが別のAjaxコールで呼び出す
私はChromeで
XMLHttpRequest.http.onreadystatechange
で未定義のプロパティ 'ID' を読み込めませんを取得しています。function searchFood() { var http = new XMLHttpRequest(); var foodID = 'a1e1c125'; var foodApiKey = 'c84a720e4f1750b59ce036329fccdc00'; var foodMethod = 'GET'; var url = 'http://api.yummly.com/v1/api/recipes?_app_id=' + foodID + '&_app_key=' + foodApiKey + '&q=scandinavian'; http.open(foodMethod, url); http.onreadystatechange = function() { if (http.readyState == XMLHttpRequest.DONE && http.status === 200) { var foodData = JSON.parse(http.responseText); var foodName = foodData.matches[0].recipeName; console.log(foodData); for (var i = 0; foodData.matches.length; i++) { var recipeId = foodData.matches[i].id; console.log(recipeId); } function getRecipe() { var http = new XMLHttpRequest(); var foodID = 'a1e1c125'; var foodApiKey = 'c84a720e4f1750b59ce036329fccdc00'; var foodMethod = 'GET'; var url = 'http://api.yummly.com/v1/api/recipe/' + recipeId + '?_app_id=' + foodID + '&_app_key=' + foodApiKey; http.open(foodMethod, url); http.onreadystatechange = function() { if (http.readyState == XMLHttpRequest.DONE && http.status === 200) { var data = JSON.parse(http.responseText); console.log(data); } else if (http.readyState === XMLHttpRequest.DONE) { alert("something went wrong"); } }; http.send(); }; } else if (http.readyState === XMLHttpRequest.DONE) { alert('Something went wrong') } }; http.send(); };
任意のヒントをいただければ幸いです、ありがとう
が欠落している、常に真
である。foodData.matches。長さ; i ++) ' – epascarello
可能であれば、JavaScriptの約定を使用してください。 https://github.com/kriskowal/qまたは少なくともjQuery。コードはもっと管理しやすいIMHOになります。 – Raptor