Answers for "fetch html from url"

1

fetch url in javascript

fetch('https://api.github.com/users/kipngetich33')
  .then(response => response.json())
  .then(formatedResponse =>  console.log(formatedResponse))
//NB please replace url with your own
Posted by: Guest on June-30-2021
0

fetch html from url

fetch('/about').then(function (response) {
	// The API call was successful!
	return response.text();
}).then(function (html) {

	// Convert the HTML string into a document object
	var parser = new DOMParser();
	var doc = parser.parseFromString(html, 'text/html');

	// Get the image file
	var img = doc.querySelector('img');
	console.log(img);

}).catch(function (err) {
	// There was an error
	console.warn('Something went wrong.', err);
});
Posted by: Guest on June-30-2020

Browse Popular Code Answers by Language