-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscript.js
More file actions
47 lines (41 loc) · 1.31 KB
/
Copy pathscript.js
File metadata and controls
47 lines (41 loc) · 1.31 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
// 1. Berkenalan dengan object js dan merubah dari object ke JSON //
//
// var mahasiswa = [
// {
// nama : "Hermawan Luthfi Nugroho",
// nrp : "32523523523523",
// email: "hermawan.luthfi@gmail.com"
// },
// {
// nama : "Hermawan Luthfi Nugroho",
// nrp : "32523523523523",
// email: "hermawan.luthfi@gmail.com"
// },
// {
// nama : "Hermawan Luthfi Nugroho",
// nrp : "32523523523523",
// email: "hermawan.luthfi@gmail.com"
// },
// ]
// console.log("=== ISI DARI VARIABLE MAHASISWA ===");
// console.log(mahasiswa);
// console.log("=== ISI DARI VARIABLE MAHASISWA SETELAH STRINGIFY ===");
// // JSON.stringify -> digunakan untuk mengubah dari OBJECT ke JSON //
// console.log(JSON.stringify(mahasiswa));
// 2. Merubah json ke object dengan Ajax //
//
// let xhr = new XMLHttpRequest();
// xhr.onreadystatechange = function () {
// if(xhr.readyState == 4 && xhr.status == 200){
// // JSON.parse -> digunakan untuk mengubah dari JSON ke OBJECT //
// let mahasiswa = JSON.parse(this.responseText);
// console.log(mahasiswa);
// }
// }
// xhr.open('GET', 'json/coba.json', true);
// xhr.send();
// 3. Menggunakan JQuery //
//
$.getJSON('json/coba.json', function(data){
console.log(data);
});