how to access the result of fetch promise code example
Example 1: javascript fetch api
fetch('http://example.com/movies.json')
.then((response) => {
return response.json();
})
.then((data) => {
console.log(data);
});
Example 2: fetch api template
//fetch api template
const fetchData=(inputs)=>{
fetch('https://example.com/api', {
method: 'post',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(inputs)
})
.then(function(response) {
return response.json();
})
.then(function(data) {
ChromeSamples.log(data.whatever);
});
}
Example 3: javascript fetch get data from promise
var x = fetch(SOME_URL, SOME_POST_DATA)
.then((response) => response.json())
.then((responseJSON) => {
// do stuff with responseJSON here...
console.log(responseJSON);
});