-
-
Save giridharmb/97c88d028d2c1c4c903eb91ff91ac4c9 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