File tree Expand file tree Collapse file tree 1 file changed +19
-0
lines changed
Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change 9191 }
9292 sDisplay . textContent = opts ;
9393 }
94+
95+ function fetchExternalData ( ) {
96+ const dataDisplay = document . getElementById ( 'external-data-display' ) ;
97+ fetch ( 'https://jsonplaceholder.typicode.com/todos/1' )
98+ . then ( ( response ) => response . json ( ) )
99+ . then ( ( data ) => {
100+ dataDisplay . textContent = 'External data: ' + data . title ;
101+ } )
102+ . catch ( ( error ) => {
103+ console . error ( 'Error:' , error ) ;
104+ alert ( 'API call failed. Check console for error.' ) ;
105+ } ) ;
106+ }
94107 </ script >
95108 </ head >
96109
207220 </ select >
208221 </ td >
209222 </ tr >
223+ < tr >
224+ < td > < button type ="button " onclick ="fetchExternalData() "> Fetch external data</ button > </ td >
225+ < td >
226+ < p id ="external-data-display "> External data: ?</ p >
227+ </ td >
228+ </ tr >
210229 </ table >
211230
212231 < div id ="off-screen " style ="position: absolute; top: 150vh; left: 100px "> Off page div</ div >
You can’t perform that action at this time.
0 commit comments