-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
37 lines (33 loc) · 1.15 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
<html>
<body onload="renderHello()">
<h1>Questo è un esempio di come funziona Mustache.</h1>
<p>Il codice sorgente lo puoi trovare <a href="https://github.com/OlecsandrKirpa/Simple_mustache_example">qui</a></p>
<div id="target">Loading...</div>
<script id="template" type="x-tmpl-mustache">
</script>
<script src="https://unpkg.com/mustache@latest"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
</body>
</html>
<script>
function ajaxReq(){
return $.ajax({
url: "https://pokeapi.co/api/v2/pokemon/1",
dataType: "json"
})
}
function renderHello() {
// console.log($(document))
let moves = {element: []};
ajaxReq().done(function(response){
console.log(response.moves)
moves["element"] = response.moves;
});
fetch('template.mustache')
.then((response) => response.text())
.then((template) => {
var rendered = Mustache.render(template, moves);
document.getElementById('target').innerHTML = rendered;
});
}
</script>