William Brown 7 lat temu
rodzic
commit
63b509c536
2 zmienionych plików z 27 dodań i 3 usunięć
  1. 4
    3
      index.html
  2. 23
    0
      js/index.js

+ 4
- 3
index.html Wyświetl plik

@@ -6,6 +6,7 @@
6 6
     <title>Import Local JSON Data | Zipcode Wilmington</title>
7 7
 </head>
8 8
 <body>
9
+    
9 10
     <header class="main-header group">
10 11
         <div class="title"><h1>Zipcode Wilmington<br>Javascript Lab - Fall 2015</h1></div>
11 12
         <div class="lesson-link"><img src="./images/logos/js_logo.png" alt="Javascript"/></div>
@@ -33,10 +34,10 @@
33 34
         <p>Use <code>document.getElementById('result').innerHTML += <i>your_output</i>;</code> to write the movie's info to the page.</p>
34 35
         <p>Append <code>"&ltbr&gt"</code> to output code to create a new line</p>
35 36
     </article>
36
-
37
-    <section>
37
+        <section>
38 38
     	<h1>Movie Information</h1>
39 39
     	<div id="result"></div>
40
-    </section>
40
+        <script src="./js/index.js"></script>
41
+        </section>
41 42
 </body>
42 43
 </html>

+ 23
- 0
js/index.js Wyświetl plik

@@ -0,0 +1,23 @@
1
+var request = new XMLHttpRequest();
2
+
3
+request.open('GET','https://data.sfgov.org/api/views/yitu-d5am/rows.json?accessType=DOWNLOAD');
4
+request.onreadystatechange = function(){
5
+	if((request.status === 200) && (request.readyState === 4)){
6
+		console.log(request.responseText);
7
+		var myArr = JSON.parse(this.responseText);
8
+		let movies = myArr.data;
9
+
10
+		var output = '';
11
+
12
+		for(let i = 0; i < movies.length; i++){
13
+			if(movies[i].includes('Golden Gate Bridge')){
14
+				output += 'Title:' + movies[i][8] + '<br>';
15
+				output += 'Year Released:' + movies[i][9] + '<br>';
16
+				output += 'Production Company:' + movies[i][12] + '<br>' + '<br>';
17
+			}
18
+		} 
19
+		document.getElementById('result').innerHTML += output;
20
+	}
21
+};
22
+
23
+request.send();