Skip to content

Instantly share code, notes, and snippets.

@pangyuteng
Last active January 6, 2024 01:52
Show Gist options
  • Save pangyuteng/56adee9cf31f7bb2e768779f9387e176 to your computer and use it in GitHub Desktop.
Save pangyuteng/56adee9cf31f7bb2e768779f9387e176 to your computer and use it in GitHub Desktop.
notes on native javascript

fetch

function exampleFetch(){

fetch('https://reqres.in/api/users/2').then(function(response) {
    return response.text();
}).then(function(string) {
    console.log(string);
    document.getElementById("my-div-id").innerHTML=string;
}).catch(function(err) {  
    console.log('Fetch Error', err);  
});

}
exampleFetch();


async


async function exampleFetch() {
    const response = await fetch('https://reqres.in/api/users/2');
    const json = await response.json();
    console.log(json);
}

exampleFetch()

additional refs

@pangyuteng
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment