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

Pierre Smith
Pierre Smith
11,842 Points

Request call not populating assigned object properly

I'm getting the error SyntaxError: Unexpected end of input(…) when i fetch from forecast.io.

when I had mode to standard cors I get a "No 'Access-Control-Allow-Origin' header is present on the requested resource.? error. so I set it to no-cors...

Afterwards I got a Unexpected end of input(…) pointing to the req.json() line

I thought that maybe I didn't have to .json() the request but that just ended up giving me a null response.

I'm out of options PLEASE I NEED HELP!

function fetchForecast(location) {
  // console.log("fetchForecast: ", location);
  var URL = `${FORECAST_URL}/${location.lat},${location.lng}?callback=?`
  return dispatch => {
    dispatch(requestForecast(location))
    return fetch(URL,{mode: 'no-cors'}).then(req => req.json())
                                       .then(json => dispatch(requestSuccess(location, json)))
                                       .catch(function(error){
                                         dispatch(requestFailed(location))
                                         console.log('REQUEST FAILED: ',error)
                                       })
  }
}