Advertisement
leors

Read JSON with jQuery (html file)

May 31st, 2015
297
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 0.64 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.     <meta charset="utf-8" />
  5.     <title>JSON Sample</title>
  6. </head>
  7. <body>
  8.     <div id="placeholder"></div>
  9.     <script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
  10.     <script>
  11.         // get file 'data.json' where http://pastebin.com/GjTGiFRy
  12.         $.getJSON('data.json', function(data) {
  13.             var output="<ul>";
  14.             for (var i in data.users) {
  15.                 output+="<li>" + data.users[i].firstName + " " + data.users[i].lastName + "–" + data.users[i].joined.month+"</li>";
  16.             }
  17.             output+="</ul>";
  18.             document.getElementById("placeholder").innerHTML=output;
  19.         });
  20.     </script>
  21. </body>
  22. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement