Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

281
Views
why does the fetch request not work when I try to fetch a markdown file?

I am trying to display a markdown file from my computer to the browser window with fetch, but the response (text) is undefined, why is this happening? I leave a codepen with my code.

https://codepen.io/matiasConchaSoto/pen/popvQgp

<main>
 <h1>Blog con Markdown y ShowDown</h1>
</main>

<script src="https://cdnjs.cloudflare.com/ajax/libs/showdown/2.0.3/showdown.min.js"></script>
<script>
 const d = document,
 $main = d.querySelector("main");

 fetch("./assetsPropios/javascript.md")
 .then(res => {
   console.log(res);
   res.ok ? res.text() : Promise.reject(res);
})
 .then(text => {
   console.log(text);
   $main.innerHTML = text;
 })
 .catch(err => {
   console.log(err);
   let message = err.statusText || "Ocurrió un error";
   $main.innerHTML = `Error ${err.status}: ${message}`;
 });
</script>

somebody help me please.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

The first .then() has a missing return.

Try:

return res.ok ? res.text() : Promise.reject(res);

Even better, something like:

if(res.ok) {
    return res.text(); 
} else {
    throw new Error(res.statusText); // or some message of your own choice.
}
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!