< 1 min read
The Fetch API interface allows web browser to make HTTP requests to web servers. No need for XMLHttpRequest anymore.
The Fetch API interface allows web browser to make HTTP requests to web servers.
No need for XMLHttpRequest anymore.
The numbers in the table specify the first browser versions that fully support Fetch API:
The example below fetches a file and displays the content:
fetch(file) .then(x => x.text()) .then(y => myDisplay(y))
Since Fetch is based on async and await, the example above might be easier to understand like this:
async function getText(file) { let x = await fetch(file); let y = await x.text(); myDisplay(y); }
Or even bettter: Use understandable names instead of x and y:
async function getText(file) { let myObject = await fetch(file); let myText = await myObject.text(); myDisplay(myText); }
Powered by BetterDocs
You must be logged in to post a comment.