Last active
February 26, 2022 03:53
-
-
Save anil-pace/4a2d4a9308b2e424dff77a21cd655a9c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8" /> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0" /> | |
| <title>Document</title> | |
| </head> | |
| <body> | |
| <button id="myBtn">fetch it</button> | |
| <script> | |
| /* using fetch(promises) */ | |
| document.getElementById("myBtn").onclick = () => { | |
| fetch(url) | |
| .then((data) => { | |
| return data.json(); | |
| }).then((res) => { | |
| console.log(res); | |
| }).catch(err=>{ | |
| // handle any kind of error | |
| console.log(err); | |
| }) | |
| }; | |
| /* | |
| document.getElementById("myBtn").onclick = async () => { | |
| var data = await fetch(url); | |
| var result = await data.json(); | |
| console.log(result); | |
| }; | |
| */ | |
| </script> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment