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+ function fetchJSON ( url ) {
2+ let xhr = new XMLHttpRequest ( ) ;
3+ xhr . open ( 'GET' , url ) ;
4+ xhr . responseType = 'json' ;
5+ xhr . onreadystatechange = ( ) => {
6+ if ( xhr . readyState === 4 ) {
7+ if ( xhr . status < 400 ) {
8+ return ( xhr . response ) ;
9+ } else {
10+ console . log ( 'failled' ) ;
11+ }
12+ }
13+ } ;
14+ xhr . send ( ) ;
15+ }
16+
17+
18+
19+ let value = fetchJSON ( 'http://api.nobelprize.org/v1/prize.json?year=2017' ) ;
20+ console . log ( value ) ;
Original file line number Diff line number Diff line change 1+ <!DOCTYPE html>
2+ < html >
3+ < head >
4+ < meta charset ="utf-8 " />
5+ < meta http-equiv ="X-UA-Compatible " content ="IE=edge ">
6+ < title > HYFJ3W1</ title >
7+ < meta name ="viewport " content ="width=device-width, initial-scale=1 ">
8+ < link rel ="stylesheet " href ="https://cdnjs.cloudflare.com/ajax/libs/flexboxgrid/6.3.1/flexboxgrid.min.css ">
9+ < script src ="script.js "> </ script >
10+ </ head >
11+ < body >
12+ </ body >
13+ </ html >
You can’t perform that action at this time.
0 commit comments