#31 jaejoson JSON-Lab2

Open
jaejoson wants to merge 1 commits from jaejoson/JSON-Lab-2:master into master
2 changed files with 20 additions and 1 deletions
  1. 2
    1
      index.html
  2. 18
    0
      javaScript.js

+ 2
- 1
index.html View File

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

+ 18
- 0
javaScript.js View File

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