Kevin Powell - CommunityKP-C
Kevin Powell - Community3y ago
55 replies
Matt

Failed to Fetch (JS)

A friend of mine sent me a website and I was curious as to how they were getting data. I found an API which I'm playing around with fetch data using JavaScript. I'm attempting to read an API, but it returns "TypeError: Failed to fetch"

Here's my code:

let api = "https://users.roblox.com/v1/users/4060137991";

function fetchData() {
    fetch(api)
    .then(response => console.log(response))
    .catch(err => console.log("error:" + err))
}

fetchData()


Typing the API in browser returns data, but when I run this function it returns an error. What am I doing wrong?
Was this page helpful?