index.html 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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">
  34. <script>
  35. var http = new XMLHttpRequest();
  36. http.onreadystatechange = function() {
  37. if (this.readyState === 4 && this.status === 200) {
  38. let jsonData = JSON.parse(http.responseText);
  39. let movieData = jsonData.data;
  40. console.log(movieData);
  41. movieInfoFunction(movieData);
  42. }
  43. };
  44. http.open("GET", "https://data.sfgov.org/api/views/yitu-d5am/rows.json?accessType=DOWNLOAD", true);
  45. http.send();
  46. function movieInfoFunction(arr){
  47. let out = "";
  48. let i;
  49. for (i = 0; i < arr.length; i++) {
  50. if (arr[i][10] === "Golden Gate Bridge") {
  51. out += arr[i][8] + " " + arr[i][9] + " " + arr[i][13]+ "<br>";
  52. }
  53. }
  54. document.getElementById("result").innerHTML = out;
  55. }
  56. </script>
  57. </div>
  58. </section>
  59. </body>
  60. </html>