Jennifer Chao 6 years ago
parent
commit
a19b60e914
2 changed files with 23 additions and 1 deletions
  1. 20
    0
      httprequest.js
  2. 3
    1
      index.html

+ 20
- 0
httprequest.js View File

@@ -0,0 +1,20 @@
1
+let httpRequest = new XMLHttpRequest();
2
+
3
+httpRequest.open("GET", "https://data.sfgov.org/api/views/yitu-d5am/rows.json?accessType=DOWNLOAD", true);
4
+
5
+httpRequest.onreadystatechange = function () {
6
+
7
+    if ((httpRequest.readyState === 4) && (httpRequest.status === 200)) {
8
+
9
+        let jsonData = JSON.parse(httpRequest.responseText).data;
10
+
11
+        for (let i = 0; i < jsonData.length; i++) {
12
+            if (jsonData[i][10] === "Golden Gate Bridge") {
13
+                document.getElementById('result').innerHTML += (jsonData[i][8] + " (" + jsonData[i][9] + ")<br>Produced by "
14
+                    + jsonData[i][12] + "<br><br>");
15
+            }
16
+        }
17
+    }
18
+};
19
+
20
+httpRequest.send();

+ 3
- 1
index.html View File

@@ -36,7 +36,9 @@
36 36
 
37 37
     <section>
38 38
     	<h1>Movie Information</h1>
39
-    	<div id="result"></div>
39
+    	<div id="result">
40
+        </div>
40 41
     </section>
42
+    <script src="httprequest.js" type="text/javascript"></script>
41 43
 </body>
42 44
 </html>