-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
54 lines (46 loc) · 1.69 KB
/
index.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
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Ajax quest challenge</title>
<link rel="icon" type="image/png" href="favicon.png" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.1/normalize.min.css">
<link rel='stylesheet' href='https://unpkg.com/[email protected]/css/bulma.min.css'>
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.5.0/css/all.css"
integrity="sha384-B4dIYHKNBt8Bc12p+WXckhzcICo0wtJAoU8YZTY5qE0Id1GSseTk6S+L3BlXeVIU" crossorigin="anonymous">
<style>
</style>
</head>
<body>
<section class="section">
<div class="container">
<h1 class="title">Chuck Norris Jokes</h1>
<p>Reload for another joke!</p>
<div class="content" id="chuck-norris">
</div>
</div>
</section>
<!-- We need to load axios first! -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/axios/0.19.0/axios.min.js" integrity="sha256-S1J4GVHHDMiirir9qsXWc8ZWw74PHHafpsHp5PXtjTs=" crossorigin="anonymous"></script>
<script>
function fetchChuckJSON() {
const url = `https://api.chucknorris.io/jokes/random`;
axios.get(url)
.then(function(response) {
return response.data; // SUBTLE difference with Fetch: response.data instead of response.json()
})
.then(function(joke) {
console.log('data decoded from JSON:', joke);
// Build a block of HTML
const chuckHtml = `
<p><strong>${joke.value}</strong></p>
<img src="${joke.icon_url}" />
`;
document.querySelector('#chuck-norris').innerHTML = chuckHtml;
});
}
fetchChuckJSON();
</script>
</body>
</html>