-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapijquery.js
33 lines (30 loc) · 1.03 KB
/
apijquery.js
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
// document.getElementById('getjson').addEventListener('click', getjson());
$(document).ready(function(){
$("#output").hide();
});
function getjson1(){
$("#output").show();
$(".form").hide();
var query = document.getElementById('findfor').value;
var url = "https://api.spoonacular.com/recipes/guessNutrition?title="+query+"&apiKey=35d3f922c81b4f0aa8297c313f1934cb"
var settings = {
"url": url,
"method": "GET",
"timeout": 0,
"headers": {
"Cookie": "__cfduid=dcfeba49845c9812e1f7950280e3ac0cd1590416809"
},
};
$.ajax(settings).done(function (response) {
console.log(response);
var obj=response;
document.getElementById('1').innerHTML=obj.calories.value+" "+obj.calories.unit;
document.getElementById('2').innerHTML=obj.fat.value+" "+obj.fat.unit;
document.getElementById('3').innerHTML=obj.protein.value+" "+obj.protein.unit;
document.getElementById('4').innerHTML=obj.carbs.value+" "+obj.carbs.unit;
});
}
function again(){
$("#output").hide();
$(".form").show();
}