Practice.html 2.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <link href="./css/style.css" type="text/css" rel="stylesheet">
  6. <title>Import Local JSON Data | Zipcode Wilmington</title>
  7. </head>
  8. <body>
  9. <header class="main-header group">
  10. <div class="title"><h1>Zipcode Wilmington<br>Javascript Lab - Fall 2015</h1></div>
  11. <div class="lesson-link"><img src="./images/logos/js_logo.png" alt="Javascript"/></div>
  12. <div class="zip-link"><img src="./images/logos/zip_logo.jpg" alt="Zipcode Wilmington"/></div>
  13. </header>
  14. <article>
  15. <h1>Instructions</h1>
  16. <p>Us the <code>XMLHttpRequest()</code> to receive the remote json feed from the following website<br>
  17. https://data.sfgov.org/api/views/yitu-d5am/rows.json?accessType=DOWNLOAD
  18. </p>
  19. <p>The json feed list movies made in San Francisco</p>
  20. <p>Write the following info for each movie to the webpage:
  21. <ul>
  22. <li>movie title</li>
  23. <li>release year</li>
  24. <li>production company</li>
  25. </ul>
  26. </p>
  27. <p>Only list movies that were made at the Golden Gate Bridge</p>
  28. <p>Use <code>document.getElementById('result').innerHTML += <i>your_output</i>;</code> to write the movie's info to the page.</p>
  29. <p>Append <code>"&ltbr&gt"</code> to output code to create a new line</p>
  30. </article>
  31. <section>
  32. <h1>Movie Information</h1>
  33. <div id="result"></div>
  34. </section>
  35. <script>
  36. var xmlhttp = new XMLHttpRequest();
  37. var url = "https://data.sfgov.org/api/views/yitu-d5am/rows.json?accessType=DOWNLOAD";
  38. var data;
  39. var listGateMovies = "";
  40. xmlhttp.open("GET", url, true);
  41. xmlhttp.onreadystatechange = function () {
  42. if (xmlhttp.readyState == 4 && xmlhttp.status === 200){
  43. data = JSON.parse(this.responseText);
  44. var movieArr = data.data;
  45. movieFunction(movieArr);
  46. }
  47. }
  48. xmlhttp.send();
  49. function movieFunction(movieArr) {
  50. for(var i = 0; i < movieArr.length; i++) {
  51. if (movieArr[i][10] === "Golden Gate Bridge") {
  52. listGateMovies +=
  53. movieArr[i][8] + ' ' +
  54. movieArr[i][9] + ' ' +
  55. movieArr[i][12] + '<br>';
  56. }
  57. }
  58. document.getElementById("result").innerText = listGateMovies;
  59. }
  60. </script>
  61. </body>
  62. </html>