fetch api get html response code example
Example 1: How to Use the JavaScript Fetch API to Get Data
fetch('http://api.steampowered.com/ISteamUserStats/GetGlobalAchievementPercentagesForApp/v0002/?gameid=221380')
.then(function(response) {
return response.json();
})
.then(function(myJson) {
console.log(JSON.stringify(myJson));
});
Example 2: http request javascript fetch
fetch('http://example.com/movies.json')
.then(response => response.json())
.then(data => console.log(data));
Example 3: get data from fetch response html
fetch('/about').then(function (response) {
return response.text();
}).then(function (html) {
var parser = new DOMParser();
var doc = parser.parseFromString(html, 'text/html');
var img = doc.querySelector('img');
console.log(img);
}).catch(function (err) {
console.warn('Something went wrong.', err);
});