Guest User

Untitled

a guest
Dec 17th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Assignment 6</title>
  6. <style type="text/css">
  7. #getResults li{
  8. color: blue;
  9. text-decoration: underline;
  10. cursor: pointer;
  11. }
  12. li{
  13. list-style-type: none;
  14. }
  15. </style>
  16. </head>
  17. <body>
  18.  
  19. <button id="getList">Get Data</button>
  20. <div id="race-names"></div>
  21. <div>
  22. <ul id='getResults'></ul>
  23. </div>
  24. <div>
  25. <ul id='showResults'></ul>
  26. </div>
  27. <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
  28. <script type="text/javascript" src="javascript.js"></script>
  29.  
  30. </body>
  31. </html>
  32.  
  33. var raceContainer = document.getElementById("getResults");
  34. var btn = document.getElementById("getList");
  35.  
  36. btn.addEventListener("click", function(){
  37.  
  38. var ourRequest = new XMLHttpRequest();
  39. ourRequest.open('GET', 'http://itweb.fvtc.edu/wetzel/marathon/races/');
  40. ourRequest.onload = function() {
  41. var ourData = JSON.parse(ourRequest.responseText);
  42. renderHTML(ourData);
  43. };
  44. ourRequest.send();
  45.  
  46. });
  47.  
  48. function renderHTML(data) {
  49. var htmlString = "";
  50.  
  51. for (i = 0; i < data.length; i++){
  52. htmlString += "<p>" + data[i].race_name + ".</p>";
  53.  
  54. }
  55.  
  56. raceContainer.insertAdjacentHTML('beforeend', htmlString);
  57.  
  58. }
Add Comment
Please, Sign In to add comment