I am totally new to web development if somebody can help me to start to use Fetch API. Can I run the HTML and vanilla JS (with JS Fetch API functionality) on my windows computer? I was looking around and found visual studio code and a live server. It looks like it can load the page on the server but still, it is not clear what kind of JS library I should include for enabling Fetch API. I just want to execute the following code on my laptop (would be nice if I don't use any JS library though I am not sure if it is possible or not)
<script> let file = "fetch_info.txt" //assuming the file is located in my server fetch (file) .then(x => x.text()) .then(y => document.getElementById("demo").innerHTML = y); </script>
Juan Pablo Isaza
The issue is that the fetch method needs a proper resource path, example:
cdn.example.org/files/fetch_info.txt with the path of your file, in your case it would most likely be on localhost!
Read more about the fetch method on mdn