@@ -8,6 +8,21 @@ function pasteQuery() {
88
99document . addEventListener ( 'DOMContentLoaded' , pasteQuery ) ;
1010
11+ // this function accepts an {object} and returns the contents displayed to the page
12+ function displayResults ( jsonData ) {
13+ // results is an array of n items
14+ let results = jsonData [ 'results' ] ;
15+
16+ results . forEach ( ( element ) => {
17+ let item = JSON . stringify ( element ) ;
18+ // you can now access element.body, element.lecture, element.timestamp, element.week
19+ document . getElementById ( 'results-area' ) . innerText = element . body ;
20+
21+ // create a new div area for each element
22+ // insert into that div, elements for each body/lecture/timestamp/week
23+ } ) ;
24+ }
25+
1126console . log ( 'made it to tabs' ) ;
1227// test hitting our local server
1328fetch ( 'http://localhost:5000/test' )
@@ -16,6 +31,13 @@ fetch('http://localhost:5000/test')
1631 } )
1732 . then ( function ( jsonResponse ) {
1833 console . log ( jsonResponse ) ;
34+ // document.getElementById('results-area').innerText = JSON.stringify(
35+ // jsonResponse['results'][0]
36+ // );
37+
38+ // document.getElementById('results-area').innerText =
39+ // JSON.stringify(jsonResponse);
40+ displayResults ( jsonResponse ) ;
1941 } )
2042 . catch ( function ( error ) {
2143 console . log ( 'Error: ' + error ) ;
0 commit comments