Advertisement
Guest User

Untitled

a guest
Apr 25th, 2014
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>Home Page</title>
  5.  
  6. <link href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">
  7.  
  8. </head>
  9. <body>
  10.  
  11. ...
  12. <ul class="list-unstyled" id="itemList">
  13. <!-- JQuery function will be called when DOM is ready -->
  14. </ul>
  15. ...
  16.  
  17. <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
  18. <script src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js">/script>
  19. <script src="my.js"></script>
  20. <script>
  21. $( document ).ready("fillInData('text.json')");
  22. </script>
  23. </body>
  24. </html>
  25.  
  26. function fillInData (dataFile) {
  27. // remove any existing content
  28. var ft = $('#itemList');
  29. ft.empty();
  30.  
  31. // populate new stuff from a co-located JSON file
  32. var htmlString = "";
  33. $.getJSON(dataFile, function(data) {
  34. $.each(data.items, function(i, item) {
  35. htmlString += '<li>' + item.name + ...;
  36. ...
  37. htmlString += '</li>'
  38. });
  39. });
  40. ft.innerHTML = htmlString;
  41. }
  42.  
  43. $(document).ready(function() {
  44. fillInData('text.json');
  45. });
  46.  
  47. $.getJSON(dataFile, function(data) {
  48. var htmlString = "";
  49.  
  50. $.each(data.items, function(i, item) {
  51. htmlString += '<li>' + item.name + ...;
  52. ...
  53. htmlString += '</li>'
  54. });
  55.  
  56. ft.html(htmlString); // it's a jQuery object, and it's async
  57.  
  58. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement