I need some basic help figuring out how to make a call to the Yummly API.
I understand JSON is not JSONP and I'm trying to understand the difference but I'm really struggling because I'm not even sure where to start.
I'm trying to do something very simple with the api, I just want to print the results to the log. If I can get to that point I'm fairly confident I can understand the difference.
I need help understanding what to put into my HTML file and how to structure my fetch so that I don't get another CROSS-ORIGIN-CONTROL-ERROR(i'm not sure exactly what the error was)
I think there is a way to actually just request the api with a JSON response and I think that would solve my issues. Either way I can't seem to figure out how to do that. Any help would be greatly appreciated!
fetch("https://api.yummly.com/v1/api/", {
headers: {
"Content-Type": "application/json",
"X-Yummly-App-ID": "29bc3e83",
"X-Yummly-App-Key": "e47af4293b45524b06ac7f4f37b20da4",
"Access-Control-Allow-Origin": true
}
}).then(function(data) {
console.log(data)
}).catch(function(error) {
console.log(error);
})
Failed to load https://api.yummly.com/v1/api/: Response to preflight request doesn't pass access control check: The 'Access-Control-Allow-Origin' header has a value 'null' that is not equal to the supplied origin. Origin 'null' is therefore not allowed access. Have the server send the header with a valid value, or, if an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
EDIT:
I have figured out how to do this with jQuery.
function displayRecipes(){
$.ajax({
url: link(keyword()),
type: "GET",
dataType: "JSONP"
}).success(function(yumData){
yumData.matches.forEach(function(recipe){
generateThumbnailFor(recipe);
});
});
};
I don't really want to use jQuery though. Can anyone help me figure out how to do this using plain javascript?