search data from json file using javascript

Solutions on MaxInterview for search data from json file using javascript by the best coders in the world

showing results for - "search data from json file using javascript"
Nele
16 Aug 2018
1<html lang="en">
2  
3<head>
4    <meta charset="UTF-8">
5    <title>GFG User Details</title>
6  
7    <!-- INCLUDING JQUERY-->
8    <script src=
9"https://code.jquery.com/jquery-3.5.1.js">
10    </script>
11  
12    <!-- CSS FOR STYLING THE PAGE -->
13    <style>
14        table {
15            margin: 0 auto;
16            font-size: large;
17            border: 1px solid black;
18        }
19  
20        h1 {
21            text-align: center;
22            color: #006600;
23            font-size: xx-large;
24            font-family: 'Gill Sans', 
25                'Gill Sans MT', ' Calibri', 
26                'Trebuchet MS', 'sans-serif';
27        }
28  
29        td {
30            background-color: #E4F5D4;
31            border: 1px solid black;
32        }
33  
34        th,
35        td {
36            font-weight: bold;
37            border: 1px solid black;
38            padding: 10px;
39            text-align: center;
40        }
41  
42        td {
43            font-weight: lighter;
44        }
45    </style>
46</head>
47  
48<body>
49    <section>
50        <h1>GeeksForGeeks</h1>
51  
52        <!-- TABLE CONSTRUCTION-->
53        <table id='table'>
54            <!-- HEADING FORMATION -->
55            <tr>
56                <th>GFG UserHandle</th>
57                <th>Practice Problems</th>
58                <th>Coding Score</th>
59                <th>GFG Articles</th>
60            </tr>
61  
62            <script>
63                $(document).ready(function () {
64  
65                    // FETCHING DATA FROM JSON FILE
66                    $.getJSON("gfgdetails.json", 
67                            function (data) {
68                        var student = '';
69  
70                        // ITERATING THROUGH OBJECTS
71                        $.each(data, function (key, value) {
72  
73                            //CONSTRUCTION OF ROWS HAVING
74                            // DATA FROM JSON OBJECT
75                            student += '<tr>';
76                            student += '<td>' + 
77                                value.GFGUserName + '</td>';
78  
79                            student += '<td>' + 
80                                value.NoOfProblems + '</td>';
81  
82                            student += '<td>' + 
83                                value.TotalScore + '</td>';
84  
85                            student += '<td>' + 
86                                value.Articles + '</td>';
87  
88                            student += '</tr>';
89                        });
90                          
91                        //INSERTING ROWS INTO TABLE 
92                        $('#table').append(student);
93                    });
94                });
95            </script>
96    </section>
97</body>
98  
99</html>