-
Notifications
You must be signed in to change notification settings - Fork 0
/
json.html
70 lines (63 loc) · 1.59 KB
/
json.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>
<body>
<div id="id01"></div>
<br>
<div id="id02"></div>
<script>
var xmlhttp = new XMLHttpRequest();
var url = "footer.json";
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
var myArr = JSON.parse(xmlhttp.responseText);
myFunction(myArr);
}
}
xmlhttp.open("GET", url, true);
xmlhttp.send();
function myFunction(arr) {
var out = "";
var i;
for(i = 0; i < arr.length; i++) {
out += '<a href="' + arr[i].link + '">' +
arr[i].name + '</a><br>';
}
document.getElementById("id01").innerHTML = out;
}
</script>
<script>
var xmlhttp2 = new XMLHttpRequest();
var url2 = "topnav.json";
xmlhttp2.onreadystatechange = function() {
if (xmlhttp2.readyState == 4 && xmlhttp2.status == 200) {
var myNavArr = JSON.parse(xmlhttp2.responseText);
myNav(myNavArr);
}
}
xmlhttp2.open("GET", url2, true);
xmlhttp2.send();
function myNav(arr) {
var out = "";
var i;
for(i = 0; i < arr.length; i++) {
out += '<a href="' + arr[i].link + '">' +
arr[i].name + '</a><br>';
}
var menuhtml = "<ul class='nav navbar-nav'>";
for (i = 0; i < data.length; i++) {
menuhtml += "<li>";
if (data[i].menus) {
for (j = 0; j < data[i].menus.length; j++) {
menuhtml += "<a class='change' href='" + data[i].menus[j].link + "'/>";
}
} else {
menuhtml += "<a class='change' href='" + data[i].link + "'/>";
}
menuhtml += "</li>";
}
menuhtml += "</ul>";
document.getElementById("id02").innerHTML = menuhtml;
}
</script>
</body>
</html>