index.html 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. <script>
  32. var xhttp = new XMLHttpRequest();
  33. var url = "https://data.sfgov.org/api/views/yitu-d5am/rows.json?accessType=DOWNLOAD";
  34. xhttp.onreadystatechange = function() {
  35. if (this.readyState == 4 && this.status == 200) {
  36. var obj = this.responseText;
  37. var obj1 = JSON.parse(obj);
  38. var obj2 = obj1.data;
  39. for (var i = 0; i < obj2.length; i++) {
  40. var movies = obj2[i];
  41. if(movies[10] == "Golden Gate Bridge"){
  42. document.getElementById("result").innerHTML += movies[9] + "<br>";
  43. document.getElementById("result").innerHTML += movies[8] + "<br>";
  44. document.getElementById("result").innerHTML += movies[12] + "<br>";
  45. }
  46. }
  47. }
  48. };
  49. xhttp.open("GET",url, true);
  50. xhttp.send();
  51. </script>
  52. <section>
  53. <h1>Movie Information</h1>
  54. <div id="result"></div>
  55. </section>
  56. </body>
  57. </html>