File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ <!DOCTYPE html>
2+ < html lang ="en ">
3+ < head >
4+ < meta charset ="UTF-8 ">
5+ < meta name ="viewport " content ="width=device-width, initial-scale=1.0 ">
6+ < meta http-equiv ="X-UA-Compatible " content ="ie=edge ">
7+ < title > 06 - Type Ahead - test</ title >
8+ </ head >
9+ < body >
10+
11+ </ body >
12+
13+ < script >
14+
15+ const req_url = 'https://raw.githubusercontent.com/cn27529/JavaScript30/master/06%20-%20Type%20Ahead/TangPoetry.json' ;
16+ const my_data = [ ] ;
17+
18+ //http://soyaine.cn/JavaScript30/
19+ //https://blog.othree.net/log/2014/11/25/fetch/
20+
21+ // fetch(req_url)
22+ // .then(res => {
23+ // console.log(res.json())
24+ // })
25+ // //.then(data => my_data.push(...data))
26+
27+ fetch ( req_url ) . then ( function ( res ) {
28+ // res instanceof Response == true.
29+ if ( res . ok ) {
30+ res . json ( ) . then ( function ( data ) {
31+ console . log ( data . entries ) ;
32+ } ) ;
33+ } else {
34+ console . log ( "Looks like the response wasn't perfect, got status" , res . status ) ;
35+ }
36+ } , function ( e ) {
37+ console . log ( "Fetch failed!" , e ) ;
38+ } ) ;
39+
40+ console . log ( my_data )
41+
42+
43+
44+ </ script >
45+ </ html >
You can’t perform that action at this time.
0 commit comments