Company logo
  • Jobs
  • Bootcamp
  • About Us
  • For professionals
    • Home
    • Jobs
    • Courses
    • Questions
    • Teachers
    • Bootcamp
  • For business
    • Home
    • Our process
    • Plans
    • Assessments
    • Payroll
    • Blog
    • Calculator

0

56
Views
Why does fetch with only 1 then not work here?
function postFetch(data) {
  document.getElementById('test').innerHTML = data.name;
}

//fetch("test").then(data=>data.json()).then(res=>{postFetch(res)});
fetch("test").then(data => postFetch(data.json()))

test is a json file with {"name":"Carla"} in it. And i have a html page with a element with id test in it, that sources this script. As it is, the page displays undefined. However, if i switch the uncomment the commented line and comment the next, it displays the intended Carla on the page. Why don't they behave the same?

7 months ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post job Plans Our process Sales
Legal
Terms and conditions Privacy policy
© 2023 PeakU Inc. All Rights Reserved.