index.html 2.7KB

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