-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrecipe.html
More file actions
87 lines (82 loc) · 3.21 KB
/
recipe.html
File metadata and controls
87 lines (82 loc) · 3.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Recipe API</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script>
<script src="https://code.jquery.com/jquery-3.4.1.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>
</head>
<body>
<!-- recipe requests go here -->
<table class="responsive-table">
<thead>
<tr>
<th>Recipe Name</th>
<th>Input 1</th>
<th>Input 2</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
<button id="submit-button">Submit</button>
<input id="cuisine-type">
<script>
$(document).ready(function () {
//adding click event listener
$("#submit-button").on("click", function () {
var app_id = "app_id=522e495c"
var app_key = "app_key=7a10cb63e3cc3756fddfd774a4d1f20b"
var cuisine = $("#cuisine-type").val() || 'pizza';
var url = `https://api.edamam.com/search?q=` + cuisine + `&` + app_id + `&` + app_key + `&from=0&to=3&calories=591-722&health=alcohol-free`
console.log(url);
// create a var for the chicken (user input)
// //prevents page from reloading on form submit
// event.preventDefault();
$.ajax({
url: url,
method: "GET",
dataType: 'jsonp'
}).then(function (response) {
var hits = response.hits;
console.log(response);
console.log(hits)
// var image = hits.healthLabels.image;
// var healthLabel = hits.ingredients.label;
// var caution = hits.cautions;
//var recipe =
hits.forEach(function (hit) {
console.log(hit);
var imageUrl = hit.recipe.image;
var healthLabel = hit.recipe.label;
var caution = hit.recipe.cautions;
var recipes = hit.recipe.ingredientLines;
var recipeURL = hit.recipe.totalNutrients.url;
//console.log(hits.recipe.ingredientLines);
// console.log(hits.recipe.ingredientLines.length);
var foodImage = $('<img>');
foodImage.attr('src', imageUrl);
foodImage.attr('alt', 'food image');
//console.log(Url);
// Create the new row
var newRow = $('<tr>').append(
$('<th>').text(""),
$('<td>').html('<img src="' + imageUrl + '">'),
$('<td>').text(healthLabel),
$('<td>').text(caution),
$('<td>').text(recipes),
$('<td>').text(recipeURL),
);
console.log(newRow)
// Append the new row to the table
$('.responsive-table > tbody').prepend(newRow);
});
});
});
});
</script>
</body>
</html>