Wunderground API access problem

  • 1
  • Problem
  • Updated 6 years ago
I have a question about a weird status I am getting while trying to access Wunderground through javascript.
When I make a call using the script below, I get an response back... the XMLHttpRequest.readyState is 4 but the XMLHttpRequest.status = 0.

//Global and init
var request;

//Weather data
var weekday;
var high;
var low;
var condition;
var pop;

function getWeather(latitude,longitude)
{
request = new XMLHttpRequest();
request.onreadystatechange = weatherStateChange;
if (typeof XDomainRequest != "undefined")
{
// XDomainRequest only exists in IE, and is IE's way of making CORS requests.
request = new XDomainRequest();
request.open("GET", "http://api.wunderground.com/api/66b1a...;
}
else
{
request.open("GET", "http://api.wunderground.com/api/66b1a..., true);
}
request.send(null);
}

function weatherStateChange()
{
if(request.readyState == 4 && request.status == 200)
{
alert('recieved weather data');
}
alert(request.getAllResponseHeaders());
}

Do I need to include any additional headers in my request? Maybe change the Content-Type? I have used a very similar script to access my own webservice and it works wonderfully. Any ideas?

EDIT: The post didn't show the full URL i used here it is
api.wunderground.com/api/66b1afdaedd9ea4c/forecast/q/"+latitude+","+longitude+".xml
Photo of tdesplen

tdesplen

  • 3 Posts
  • 0 Reply Likes

Posted 6 years ago

  • 1
Photo of tdesplen

tdesplen

  • 3 Posts
  • 0 Reply Likes
I read the browser log and apparently the company website i registered:

http://publish.uwo.ca

is being denied by CORS.

How can we fix this?