-
Notifications
You must be signed in to change notification settings - Fork 0
/
fetch-1.html
69 lines (65 loc) · 1.5 KB
/
fetch-1.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<style>
#cont{
display:grid;
grid-template-columns: repeat(4,1fr);
}
img{
width:100px;
height:100px;
}
</style>
<body>
<div id="cont"></div>
</body>
</html>
<script>
// let url="https://fakestoreapi.com/products"
let url="http://www.omdbapi.com/?i=tt3896198&apikey=48a05b91&t=avengers"
// let x= fetch(url)
// // console.log(x)
// x.then(function(res){
// return res.json()
// })
// .then(function(res){
// console.log(res)
// })
// .catch(function(err){
// console.log(err)
// })
async function getdata(){
try{
let res = await fetch(url);
let data= await res.json()
console.log(data)
// appenddata(data)
}
catch(err){
console.log(err)
}
}
getdata()
// const container=document.getElementById("cont")
function appenddata(data){
console.log(data)
data.map(function(elem){
let maindiv= document.createElement("div")
let image=document.createElement("img")
image.src=elem.image
let title= document.createElement("p")
title.innerText=elem.title
let price=document.createElement("p")
price.innerText=elem.price
maindiv.append(image,title,price)
container.append(maindiv)
})
}
</script>
<!-- url= -->