Services II - 404 on forecast.JSON call


#1



I was unable to progress past Services II Step 2 due to a cross-origin resource sharing (CORS) error.
After adding the required html to display the forecast data and hitting run none of the data would display.

Checking Developer Tools > Network (F12) I saw that the forcast.json request was being blocked, with this error:

XMLHttpRequest cannot load https://s3.amazonaws.com/codeacademy-content/courses/ltp4/forecast-api/forecast.json. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://codecademy9357842-29400.ccterminalcloud.com' is therefore not allowed access. The response had HTTP status code 404.

I've logged a bug report but as a workaround add the following code to MainController,js, after the closing semicolon of forecast.success.

forecast.error(function(data){
    $scope.fiveDay = {
  "city_name": "New York",
  "country": "US",
  "days": [
    {
      "datetime": 1420390800000,
      "icon": "https://s3.amazonaws.com/codecademy-content/courses/ltp4/forecast-api/sun.svg",
      "high": 68,
      "low": 37
    },
    {
      "datetime": 1420477200000,
      "icon": "https://s3.amazonaws.com/codecademy-content/courses/ltp4/forecast-api/clouds.svg",
      "high": 68,
      "low": 37
    },
    {
      "datetime": 1420563600000,
      "icon": "https://s3.amazonaws.com/codecademy-content/courses/ltp4/forecast-api/rain.svg",
      "high": 46,
      "low": 14
    },
    {
      "datetime": 1420650000000,
      "icon": "https://s3.amazonaws.com/codecademy-content/courses/ltp4/forecast-api/clouds.svg",
      "high": 46,
      "low": 28
    },
    {
      "datetime": 1420736400000,
      "icon": "https://s3.amazonaws.com/codecademy-content/courses/ltp4/forecast-api/sun.svg",
      "high": 59,
      "low": 32
    }
  ]
};
  });// end forecast.error

This will populate forecast with the correct data if the request fails.
I hope this helps other people.


#2

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.