Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

Mikhailo Rozumovskyy
Mikhailo Rozumovskyy
3,779 Points

Fetch(). How would you access Itunes feeds, it doesnt work to me.

I am trying to display Itunes top 100 songs, but an error apears in the console. The link I use: https://rss.itunes.apple.com/api/v1/us/itunes-music/top-songs/all/100/explicit.json

my code:

fetch('https://rss.itunes.apple.com/api/v1/us/itunes-music/top-songs/all/100/explicit.json')
    .then(response => response.json())
    .then(data => console.log(data.feed.results.artistName[0]))

errors i get: Failed to load https://rss.itunes.apple.com/api/v1/us/itunes-music/top-songs/all/100/explicit.json: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

index.html:1 Uncaught (in promise) TypeError: Failed to fetch Promise.then (async) (anonymous)

scripts.js:11 Fetch failed loading: GET "https://rss.itunes.apple.com/api/v1/us/itunes-music/top-songs/all/100/explicit.json".