origin is not allowed by access-control-allow-origin

  • 2
  • Problem
  • Updated 8 months ago
I am trying to get the forecast for my homepage using the code below, but when I try to load my homepage I get "XMLHttpRequest cannot load http://api.wunderground.com/api/"key".... Origin http://192.168.1.68 is not allowed by Access-Control-Allow-Origin." I have replaced the api key with key for privacy. I have used a very similar code on another website with no issues.

$.getJSON('http://api.wunderground.com/api/"key"...
{
var forcastData = {};
for (var i in json.list)
{
var forcast = json.list[i];
var dateKey = simpleforecast.forecastday.date.day;

forcastData[dateKey] =
{
'timestamp':simpleforecast.forecastday.date.day,
'temp_min':simpleforecast.forecastday.low.fahrenheit,
'temp_max':simpleforecast.forecastday.high.fahrenheit
};
}
var forecastTable = $('').addClass('forecast-table');
var opacity = 1;
for (var i in forecastData) {
var weekforecast = forecastData[i];

var row = $('').css('opacity', opacity);

row.append($('').addClass('day').html(weekforecast.timestamp));

row.append($('').addClass('temp-max').html(weekforecast.temp_max));
row.append($('').addClass('temp-min').html(weekforecast.temp_min));

forecastTable.append(row);
opacity -= 0.12;

}
$('.forecast').updateWithText(forecastTable, 1000);
});
Photo of starexplorer31

starexplorer31

  • 2 Posts
  • 0 Reply Likes

Posted 4 years ago

  • 2
Photo of starexplorer31

starexplorer31

  • 2 Posts
  • 0 Reply Likes
Issue solved. tried to delete it but it is still here for some reason.

Ps. don't use this code it has other issues in it.
Photo of Koni Kodes

Koni Kodes

  • 6 Posts
  • 0 Reply Likes
How did you resolve your issue?