-
Notifications
You must be signed in to change notification settings - Fork 0
/
movie_data.html
65 lines (64 loc) · 1.82 KB
/
movie_data.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>The Fetch API and Promises</title>
<style>
html {
height: 100%;
}
body {
background: #cc1010;
display: flex;
flex-direction: column;
height: 100%;
}
section {
background: #fff;
width: 80%;
margin: 0 auto;
padding: 20px;
flex: 1;
border-radius: 5px;
}
h1, h2 {
font-family: Georgia;
}
p {
line-height: 1.4;
font-family: Verdana;
}
pre {
white-space: pre-wrap;
}
</style>
</head>
<body>
<section>
<h1>Movie Title</h1>
<h2>Released 06 Jul 2016</h2>
<p>Plot summary</p>
<pre></pre>
</section>
<script type="text/javascript" charset="utf-8">
// the url is the location of a server that has movie data
var url = "http://www.omdbapi.com/?t=brotherhood+of+the+wolf&y=&plot=full&r=json";
// the response that comes back from the server has to be converted into
// JavaScript Object Notation (JSON), and the function below does that
function convertToJson(response) {
return response.json();
}
// once the data is converted to JSON, the following function takes the
// data and uses it to update the page
function updatePage(data){
document.querySelector("h1").innerText = data["Title"];
document.querySelector("h2").innerText = data["Released"];
document.querySelector("p").innerText = data["Plot"];
//document.querySelector("pre").innerText = JSON.stringify(data);
}
//this is the line that kicks everything off
fetch(url).then(convertToJson).then(updatePage);
</script>
</body>
</html>