I have a function that inserts an inline svg in the DOM using XMLHttpRequest() and I'm wondering if I can do the same function using fetch(). The function is...
el = document.querySelector('#foo')
var request = new XMLHttpRequest()
request.open('GET', 'bar.svg', true)
request.onreadystatechange = function() {
if (this.readyState !== 4) return
if (this.status !== 200) return
el.innerHTML = this.responseText
}
request.send()
// bar.svg is inserted in element with ID 'foo'
So, is it possible to modernize this function into something like...
fetch('bar.svg').then(...)