-
Notifications
You must be signed in to change notification settings - Fork 0
/
mvc.html
41 lines (41 loc) · 1.49 KB
/
mvc.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
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<meta charset="UTF-8">
</head>
<body>
<button id="getJokes">Get Jokes!</button>
<table id="jokesTable">
<tr class="jokeRowModel" style="display:none;">
<td id="joke"></td>
<td><button>Hide joke</button></td>
</tr>
</table>
<script>
var currentJokes = 0;
$("#getJokes").click(() => {
getJokes(10);
})
var getJokes = amount => {
$.ajax(`http://api.icndb.com/jokes/random/${amount}`)
.done(receivedJokes => {
currentJokes = amount;
$("tr").remove(".jokeRow");
receivedJokes.value.forEach(e => {
var joke = $(".jokeRowModel").clone().prop({ class: "jokeRow", style: "display:table-row;"});
joke.find("button").click(removeJoke);
joke.find("#joke").text(e.joke);
joke.appendTo("#jokesTable");
});
});
};
function removeJoke() {
$(this).parents(".jokeRow").remove();
currentJokes--;
if (currentJokes <= 0) {
getJokes(10);
}
};
</script>
</body>
</html>