Trying to access response data using fetch

后端 未结 2 1061
鱼传尺愫
鱼传尺愫 2021-02-07 21:12

I\'m trying something simple where I make a request from the front end of my app using the fetch API like so

let request = new Request(\'http://localhost:3000/a         


        
2条回答
  •  礼貌的吻别
    2021-02-07 21:51

    Okay, this works on my front end

    fetch(request).then((response) => {
        console.log(response);
        response.json().then((data) => {
            console.log(data);
        });
    });
    

    The key part was the resolution of the promise chain.

    Similar question here JavaScript fetch API - Why does response.json() return a promise object (instead of JSON)?

提交回复
热议问题