Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexample5.html
More file actions
Latest commit
87 lines (84 loc) · 4.27 KB
/
Copy pathexample5.html
File metadata and controls
87 lines (84 loc) · 4.27 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<!DOCTYPE html>
<!--/**
*
* @link https://github.com/mzm-dev
* @created September 2014
* @fb https://www.facebook.com/zakimedia
* @email mohdzaki04@gmail.com
*/-->
<html>
<head>
<metacharset="utf-8">
<metacontent="IE=edge" http-equiv="X-UA-Compatible">
<metacontent="width=device-width, initial-scale=1" name="viewport">
<metacontent="Getting started with JSON using JavaScript and jQuery" name="description">
<metacontent="Mohamad Zaki" name="author">
<metaname="viewport" content="width=device-width, initial-scale=1.0">
<scriptsrc="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<linkrel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<linkrel="stylesheet" href="http://getbootstrap.com/examples/jumbotron-narrow/jumbotron-narrow.css">
<scriptsrc="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
</head>
<body>
<divclass="container">
<divclass="header">
<ulclass="nav nav-pills pull-right">
<li><ahref="/JSON-Example/"><spanclass="glyphicon glyphicon-chevron-left"></span> Back</a></li>
<liclass="active"><ahref="https://github.com/pesima/JSON-Example">Get the code on Github now HighCharts</a></li>
</ul>
<h3class="text-muted">A JSON Tutorial | <span>Reading JSON from an external file</span></h3>
</div>
<h1>Use JavaScript</h1>
<divid="placeholder-js"></div>
<script>
$.getJSON('data.json',function(data){//external data
varoutput='<table class="table table-bordered table-hover">';
output+='<tr>'+
'<th>Nama</th>'+
'<th>Jawatan/Gred</th>'+
'<th>No Telefon/Sambungan</th>'+
'<th>Bahagian</th>'+
'<th>Unit</th>';
'<tr/>';
for(variindata.pegawai){
output+="<tr>";
output+="<td>"+data.pegawai[i].namaPenuh+"</td>";
output+="<td>"+data.pegawai[i].jawatan+"("+data.pegawai[i].gred+")</td>";
output+="<td>"+data.pegawai[i].noTelefon+"samb. "+data.pegawai[i].sambungan+"</td>";
output+="<td>"+data.pegawai[i].bahagian.nama+"</td>";
output+="<td>"+data.pegawai[i].bahagian.unit+"</td>";
output+="</tr>";
}
output+="</table>";
document.getElementById("placeholder-js").innerHTML=output;
});
</script>
<h1>Use Jquery</h1>
<divid="placeholder-jq"></div>
<script>
$.getJSON('data.json',function(data){//external data
varappenddata=[];
appenddata+='<table class="table table-bordered table-hover">';
appenddata+='<tr>'+
'<th>Nama</th>'+
'<th>Jawatan/Gred</th>'+
'<th>No Telefon/Sambungan</th>'+
'<th>Bahagian</th>'+
'<th>Unit</th>';
'<tr/>';
$.each(data.pegawai,function(i,val){
appenddata+="<tr>";
appenddata+="<td>"+val.namaPenuh+"</td>";
appenddata+="<td>"+val.jawatan+"("+val.gred+")</td>";
appenddata+="<td>"+val.noTelefon+"samb. "+val.sambungan+"</td>";
appenddata+="<td>"+val.bahagian.nama+"</td>";
appenddata+="<td>"+val.bahagian.unit+"</td>";
appenddata+="</tr>";
});
appenddata+="</table>";
$('#placeholder-jq').html(appenddata);
});
</script>
</div>
</body>
</html>